-
Notifications
You must be signed in to change notification settings - Fork 25
/
order.go
58 lines (55 loc) · 1.41 KB
/
order.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
package hitbtc
import (
"encoding/json"
"time"
)
// Order represents an order made on the exchange.
type Order struct {
ClientOrderId string `json:"clientOrderId"`
Symbol string `json:"symbol"`
Side string `json:"side"`
Status string `json:"status"`
Type string `json:"type"`
TimeInForce string `json:"timeInForce"`
Quantity float64 `json:"quantity,string"`
Price float64 `json:"price,string"`
CumQuantity float64 `json:"cumQuantity,string"`
Created time.Time `json:"createdAt"`
Updated time.Time `json:"updatedAt"`
StopPrice float64 `json:"stopPrice,string"`
Expire time.Time `json:"expireTime"`
}
func (t *Order) UnmarshalJSON(data []byte) error {
var err error
type Alias Order
aux := &struct {
Created string `json:"createdAt"`
Updated string `json:"updatedAt"`
Expire string `json:"expireTime"`
*Alias
}{
Alias: (*Alias)(t),
}
if err = json.Unmarshal(data, &aux); err != nil {
return err
}
if aux.Created != "" {
t.Created, err = time.Parse("2006-01-02T15:04:05.999Z", aux.Created)
if err != nil {
return err
}
}
if aux.Updated != "" {
t.Updated, err = time.Parse("2006-01-02T15:04:05.999Z", aux.Updated)
if err != nil {
return err
}
}
if aux.Expire != "" {
t.Expire, err = time.Parse("2006-01-02T15:04:05.999Z", aux.Expire)
if err != nil {
return err
}
}
return nil
}