-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorderbook.go
57 lines (45 loc) · 1.41 KB
/
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
53
54
55
56
57
package gobitpanda
import (
"errors"
"fmt"
"strconv"
)
// GetOrderBook gets a given instrument's order book.
func (c *Client) GetOrderBook(instrumentCode string, level int) (*OrderBook, error) {
orderbook := &OrderBook{}
if instrumentCode == "" {
return nil, errors.New("instrumentCode can not be empty")
}
if level == 0 {
level = LevelDefault
} else if level > 3 {
return nil, errors.New("level can not be > 3")
} else if level < 0 {
return nil, errors.New("level can not be < 0")
} else if level == 1 {
return nil, errors.New("For leve one please use GetOrderBookLvlOne()")
}
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s%s%s", c.APIBase, "/v1/order-book/", instrumentCode, "?level="+strconv.Itoa(level)), nil)
if err != nil {
return orderbook, err
}
if err = c.Send(req, orderbook); err != nil {
return orderbook, err
}
return orderbook, nil
}
// GetOrderBookLvlOne gets a given instrument's order book at level one
func (c *Client) GetOrderBookLvlOne(instrumentCode string) (*OrderBookLvlOne, error) {
orderbook := &OrderBookLvlOne{}
if instrumentCode == "" {
return nil, errors.New("instrumentCode can not be empty")
}
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s%s%s", c.APIBase, "/v1/order-book/", instrumentCode, "?level=1"), nil)
if err != nil {
return orderbook, err
}
if err = c.Send(req, orderbook); err != nil {
return orderbook, err
}
return orderbook, nil
}