-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtrade.go
39 lines (36 loc) · 948 Bytes
/
trade.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
package hitbtc
import (
"encoding/json"
"time"
)
// Trade represents a single trade made by a user.
type Trade struct {
Id uint64 `json:"id"`
OrderId uint64 `json:"orderId"`
ClientOrderId string `json:"clientOrderId"`
Symbol string `json:"symbol"`
Type string `json:"side"`
Price float64 `json:"price,string"`
Quantity float64 `json:"quantity,string"`
Fee float64 `json:"fee,string"`
Timestamp time.Time `json:"timestamp"`
}
// UnmarshalJSON allows the obejct to be JSON Unmarshallable.
func (t *Trade) UnmarshalJSON(data []byte) error {
var err error
type Alias Trade
aux := &struct {
Timestamp string `json:"timestamp"`
*Alias
}{
Alias: (*Alias)(t),
}
if err = json.Unmarshal(data, &aux); err != nil {
return err
}
t.Timestamp, err = time.Parse("2006-01-02T15:04:05.999Z", aux.Timestamp)
if err != nil {
return err
}
return nil
}