-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic_orderbook.go
52 lines (46 loc) · 1.06 KB
/
public_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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package bitso
import (
"encoding/json"
"errors"
"fmt"
"time"
)
type OrderBookResponse struct {
Success bool `json:"success"`
Error Error `json:"error,omitempty"`
OrderBook OrderBook `json:"payload,omitempty"`
}
type OrderBook struct {
Asks []Order `json:"asks"`
Bids []Order `json:"bids"`
UpdatedAt time.Time `json:"updated_at"`
Sequence int `json:"sequence,string"`
}
type Order struct {
Book string `json:"book"`
Price float64 `json:"price,string"`
Amount float64 `json:"amount,string"`
OID string `json:"oid,omitempty"`
}
func (api *API) OrderBook(book string, aggregate bool) (*OrderBook, error) {
if book == "" {
return nil, errors.New("There is no book specified")
}
extra := ""
if !aggregate {
extra = "&aggregate=false"
}
data, err := api.ask("order_book/?book="+book+extra, nil)
if err != nil {
return nil, err
}
ab := OrderBookResponse{}
err = json.Unmarshal(data, &ab)
if err != nil {
return nil, err
}
if api.Devel {
fmt.Printf("DATA RECEIVED: %+v\n", ab)
}
return &ab.OrderBook, nil
}