-
Notifications
You must be signed in to change notification settings - Fork 25
/
orderbook.go
33 lines (29 loc) · 659 Bytes
/
orderbook.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
package hitbtc
import (
"encoding/json"
)
// Orderbook represents an orderbook from hitbtc api.
type Orderbook struct {
Ask []OrderBookItem `json:"ask,struct"`
Bid []OrderBookItem `json:"bid,struct"`
}
// OrderBookItem for Ask and Bid field.
type OrderBookItem struct {
Price float64 `json:"price,string"`
Size float64 `json:"size,string"`
}
// UnmarshalJSON for OrderBook function
func (t *Orderbook) UnmarshalJSON(data []byte) error {
var err error
type Alias Orderbook
aux := &struct {
Timestamp string `json:"timestamp"`
*Alias
}{
Alias: (*Alias)(t),
}
if err = json.Unmarshal(data, &aux); err != nil {
return err
}
return nil
}