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