forked from go-numb/go-liquid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecution.go
104 lines (86 loc) · 2.32 KB
/
execution.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package liquid
import (
"fmt"
"strconv"
)
type Executions struct {
Models []ExecutionsModels `json:"models"`
CurrentPage int `json:"current_page"`
TotalPages int `json:"total_pages"`
}
type ExecutionsModels struct {
ID int `json:"id"`
Quantity float64 `json:"quantity,string"`
Price float64 `json:"price,string"`
TakerSide string `json:"taker_side"`
MySide string `json:"my_side"`
CreatedAt int64 `json:"created_at"`
}
func (c *Client) GetExecutionsByTimestamp(
productID int,
limit int,
timestamp int) ([]ExecutionsModels, error) {
req, err := c.newRequest("GET", "/executions", nil,
&map[string]string{
"product_id": strconv.Itoa(productID),
"limit": strconv.Itoa(limit),
"timestamp": strconv.Itoa(timestamp)})
if err != nil {
return nil, err
}
res, err := c.HTTPClient.Do(req)
if err != nil {
return nil, err
}
if res.StatusCode != 200 {
return nil, fmt.Errorf("failed to get data. status: %s", res.Status)
}
var executions []ExecutionsModels
if err := decode(res, &executions); err != nil {
return nil, err
}
return executions, nil
}
func (c *Client) GetExecutions(productID int, limit int, page int) (Executions, error) {
var executions Executions
req, err := c.newRequest("GET", "/executions", nil,
&map[string]string{
"product_id": strconv.Itoa(productID),
"limit": strconv.Itoa(limit),
"page": strconv.Itoa(page)})
if err != nil {
return executions, err
}
res, err := c.HTTPClient.Do(req)
if err != nil {
return executions, err
}
if res.StatusCode != 200 {
return executions, fmt.Errorf("failed to get data. status: %s", res.Status)
}
if err := decode(res, &executions); err != nil {
return executions, err
}
return executions, nil
}
func (c *Client) GetOwnExecutions(productID int) (Executions, error) {
var executions Executions
req, err := c.newRequest("GET", "/executions/me", nil,
&map[string]string{
"product_id": strconv.Itoa(productID),
})
if err != nil {
return executions, err
}
res, err := c.HTTPClient.Do(req)
if err != nil {
return executions, err
}
if res.StatusCode != 200 {
return executions, fmt.Errorf("failed to get data. status: %s", res.Status)
}
if err := decode(res, &executions); err != nil {
return executions, err
}
return executions, nil
}