github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/trades/authfundingtrades.go (about) 1 package trades 2 3 import ( 4 "fmt" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/convert" 7 ) 8 9 // AuthFundingTrade data structure 10 type AuthFundingTrade struct { 11 ID int64 12 Symbol string 13 MTSCreated int64 14 OfferID int64 15 Amount float64 16 Rate float64 17 Period int64 18 Maker int64 19 } 20 21 type AuthFundingTradeUpdate AuthFundingTrade 22 type AuthFundingTradeExecuted AuthFundingTrade 23 24 type AuthFundingTradeSnapshot struct { 25 Snapshot []AuthFundingTrade 26 } 27 28 // AFTFromRaw maps raw data slice to instance of AuthFundingTrade 29 func AFTFromRaw(raw []interface{}) (aft AuthFundingTrade, err error) { 30 if len(raw) < 8 { 31 return AuthFundingTrade{}, fmt.Errorf("data slice too short for funding trade: %#v", raw) 32 } 33 34 aft = AuthFundingTrade{ 35 ID: convert.I64ValOrZero(raw[0]), 36 Symbol: convert.SValOrEmpty(raw[1]), 37 MTSCreated: convert.I64ValOrZero(raw[2]), 38 OfferID: convert.I64ValOrZero(raw[3]), 39 Amount: convert.F64ValOrZero(raw[4]), 40 Rate: convert.F64ValOrZero(raw[5]), 41 Period: convert.I64ValOrZero(raw[6]), 42 Maker: convert.I64ValOrZero(raw[7]), 43 } 44 45 return 46 } 47 48 // AFTUFromRaw maps raw data slice to instance of AuthFundingTradeUpdate 49 func AFTUFromRaw(raw []interface{}) (AuthFundingTradeUpdate, error) { 50 aft, err := AFTFromRaw(raw) 51 if err != nil { 52 return AuthFundingTradeUpdate{}, err 53 } 54 55 return AuthFundingTradeUpdate(aft), nil 56 } 57 58 // AFTEFromRaw maps raw data slice to instance of AuthFundingTradeExecuted 59 func AFTEFromRaw(raw []interface{}) (AuthFundingTradeExecuted, error) { 60 aft, err := AFTFromRaw(raw) 61 if err != nil { 62 return AuthFundingTradeExecuted{}, err 63 } 64 65 return AuthFundingTradeExecuted(aft), nil 66 } 67 68 // AFTSnapshotFromRaw maps raw data slice to authenticated funding trade data structures 69 func AFTSnapshotFromRaw(raw [][]interface{}) (AuthFundingTradeSnapshot, error) { 70 if len(raw) == 0 { 71 return AuthFundingTradeSnapshot{}, fmt.Errorf("data slice too short for funding trade snapshot: %#v", raw) 72 } 73 74 snap := make([]AuthFundingTrade, 0) 75 for _, r := range raw { 76 ft, err := AFTFromRaw(r) 77 if err != nil { 78 return AuthFundingTradeSnapshot{}, err 79 } 80 snap = append(snap, ft) 81 } 82 83 return AuthFundingTradeSnapshot{Snapshot: snap}, nil 84 }