github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/fundingoffer/fundingoffer.go (about) 1 package fundingoffer 2 3 import ( 4 "fmt" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/convert" 7 ) 8 9 type Offer struct { 10 ID int64 11 Symbol string 12 MTSCreated int64 13 MTSUpdated int64 14 Amount float64 15 AmountOrig float64 16 Type string 17 Flags map[string]interface{} 18 Status string 19 Rate float64 20 Period int64 21 Notify bool 22 Hidden bool 23 Insure bool 24 Renew bool 25 RateReal float64 26 } 27 28 type New Offer 29 type Update Offer 30 type Cancel Offer 31 type Snapshot struct { 32 Snapshot []*Offer 33 } 34 35 func FromRaw(raw []interface{}) (o *Offer, err error) { 36 if len(raw) < 21 { 37 return o, fmt.Errorf("data slice too short for funding offer: %#v", raw) 38 } 39 40 o = &Offer{ 41 ID: convert.I64ValOrZero(raw[0]), 42 Symbol: convert.SValOrEmpty(raw[1]), 43 MTSCreated: convert.I64ValOrZero(raw[2]), 44 MTSUpdated: convert.I64ValOrZero(raw[3]), 45 Amount: convert.F64ValOrZero(raw[4]), 46 AmountOrig: convert.F64ValOrZero(raw[5]), 47 Type: convert.SValOrEmpty(raw[6]), 48 Status: convert.SValOrEmpty(raw[10]), 49 Rate: convert.F64ValOrZero(raw[14]), 50 Period: convert.I64ValOrZero(raw[15]), 51 Notify: convert.BValOrFalse(raw[16]), 52 Hidden: convert.BValOrFalse(raw[17]), 53 Insure: convert.BValOrFalse(raw[18]), 54 Renew: convert.BValOrFalse(raw[19]), 55 RateReal: convert.F64ValOrZero(raw[20]), 56 } 57 58 if flags, ok := raw[9].(map[string]interface{}); ok { 59 o.Flags = flags 60 } 61 62 return 63 } 64 65 func CancelFromRaw(raw []interface{}) (Cancel, error) { 66 o, err := FromRaw(raw) 67 if err != nil { 68 return Cancel{}, err 69 } 70 return Cancel(*o), nil 71 } 72 73 func NewFromRaw(raw []interface{}) (New, error) { 74 o, err := FromRaw(raw) 75 if err != nil { 76 return New{}, err 77 } 78 return New(*o), nil 79 } 80 81 func UpdateFromRaw(raw []interface{}) (Update, error) { 82 o, err := FromRaw(raw) 83 if err != nil { 84 return Update{}, err 85 } 86 return Update(*o), nil 87 } 88 89 func SnapshotFromRaw(raw []interface{}) (snap *Snapshot, err error) { 90 if len(raw) == 0 { 91 return snap, fmt.Errorf("data slice too short for funding offer: %#v", raw) 92 } 93 94 fos := make([]*Offer, 0) 95 switch raw[0].(type) { 96 case []interface{}: 97 for _, v := range raw { 98 if l, ok := v.([]interface{}); ok { 99 o, err := FromRaw(l) 100 if err != nil { 101 return snap, err 102 } 103 fos = append(fos, o) 104 } 105 } 106 default: 107 return snap, fmt.Errorf("not a funding offer snapshot") 108 } 109 110 snap = &Snapshot{Snapshot: fos} 111 return 112 }