github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/fundingtrade/fundingtrade.go (about) 1 package fundingtrade 2 3 import ( 4 "fmt" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/convert" 7 ) 8 9 type FundingTrade struct { 10 ID int64 11 Symbol string 12 MTSCreated int64 13 OfferID int64 14 Amount float64 15 Rate float64 16 Period int64 17 Maker int64 18 } 19 20 type Execution FundingTrade 21 type Update FundingTrade 22 type Snapshot struct { 23 Snapshot []*FundingTrade 24 } 25 type HistoricalSnapshot Snapshot 26 27 func FromRaw(raw []interface{}) (ft *FundingTrade, err error) { 28 if len(raw) < 8 { 29 return ft, fmt.Errorf("data slice too short for funding trade: %#v", raw) 30 } 31 32 ft = &FundingTrade{ 33 ID: convert.I64ValOrZero(raw[0]), 34 Symbol: convert.SValOrEmpty(raw[1]), 35 MTSCreated: convert.I64ValOrZero(raw[2]), 36 OfferID: convert.I64ValOrZero(raw[3]), 37 Amount: convert.F64ValOrZero(raw[4]), 38 Rate: convert.F64ValOrZero(raw[5]), 39 Period: convert.I64ValOrZero(raw[6]), 40 Maker: convert.I64ValOrZero(raw[7]), 41 } 42 43 return 44 } 45 46 func SnapshotFromRaw(raw []interface{}) (snap *Snapshot, err error) { 47 if len(raw) == 0 { 48 return snap, fmt.Errorf("data slice too short for funding trade") 49 } 50 51 fts := make([]*FundingTrade, 0) 52 switch raw[0].(type) { 53 case []interface{}: 54 for _, v := range raw { 55 if l, ok := v.([]interface{}); ok { 56 o, err := FromRaw(l) 57 if err != nil { 58 return snap, err 59 } 60 fts = append(fts, o) 61 } 62 } 63 default: 64 return snap, fmt.Errorf("not a funding trade snapshot") 65 } 66 snap = &Snapshot{ 67 Snapshot: fts, 68 } 69 70 return 71 } 72 73 func HistoricalSnapshotFromRaw(raw []interface{}) (HistoricalSnapshot, error) { 74 s, err := SnapshotFromRaw(raw) 75 if err != nil { 76 return HistoricalSnapshot{}, err 77 } 78 79 return HistoricalSnapshot(*s), nil 80 }