github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/fundinginfo/fundinginfo.go (about) 1 package fundinginfo 2 3 import ( 4 "fmt" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/convert" 7 ) 8 9 type FundingInfo struct { 10 Symbol string 11 YieldLoan float64 12 YieldLend float64 13 DurationLoan float64 14 DurationLend float64 15 } 16 17 func FromRaw(raw []interface{}) (fi *FundingInfo, err error) { 18 if len(raw) < 3 { // "sym", symbol, data 19 return fi, fmt.Errorf("data slice too short for funding info: %#v", raw) 20 } 21 22 sym, ok := raw[1].(string) 23 if !ok { 24 return fi, fmt.Errorf("expected symbol in second position of funding info: %v", raw) 25 } 26 27 data, ok := raw[2].([]interface{}) 28 if !ok { 29 return fi, fmt.Errorf("expected list in third position of funding info: %v", raw) 30 } 31 32 if len(data) < 4 { 33 return fi, fmt.Errorf("data too short: %#v", data) 34 } 35 36 fi = &FundingInfo{ 37 Symbol: sym, 38 YieldLoan: convert.F64ValOrZero(data[0]), 39 YieldLend: convert.F64ValOrZero(data[1]), 40 DurationLoan: convert.F64ValOrZero(data[2]), 41 DurationLend: convert.F64ValOrZero(data[3]), 42 } 43 44 return 45 }