-
Notifications
You must be signed in to change notification settings - Fork 0
/
orderStatus.go
140 lines (109 loc) · 3.49 KB
/
orderStatus.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package gemini
import "encoding/json"
type (
OrderStatusRequestPayload struct {
BaseRequest
OrderID int `json:"order_id"`
IncludeTrades bool `json:"include_trades"`
}
OrderStatusTrade struct {
Aggressor bool `json:"aggressor"`
Amount bool `json:"amount"`
Exchange string `json:"exchange"`
FeeAmount string `json:"fee_amount"`
FeeCurrency string `json:"fee_currency"`
IsAuctionFill bool `json:"is_auction_fill"`
OrderID string `json:"order_id"`
Price string `json:"price"`
TID int `json:"tid"`
Timestamp int64 `json:"timestamp"`
TimestampMS int64 `json:"timestampms"`
Type string `json:"type"`
}
OrderStatusResponseWithTrades struct {
OrderStatusResponse
Trades []OrderStatusTrade `json:"trades"`
}
)
// OrderStatus Returns status of order.
// WARNING: Gemini recommends using WebSocket Order Events API to receive order status changes!
// WARNING: Under the terms of the Gemini API Agreement, polling this endpoint may be subject to rate limiting.
// @see https://docs.gemini.com/rest-api/#order-status
func (c *Client) GetOrderStatus(orderID int) (resp OrderStatusResponse, err error) {
order := OrderStatusRequestPayload{
OrderID: orderID,
}
order.Nonce = c.createNonce()
order.Request = "/v1/order/status"
bodyBytes, err := json.Marshal(order)
if err != nil {
return
}
err = c.Call("POST", "/order/status", bodyBytes, &resp)
return
}
// GetOrderStatusWithTrades Returns status of order including trades.
// WARNING: Gemini recommends using WebSocket Order Events API to receive order status changes!
// WARNING: Under the terms of the Gemini API Agreement, polling this endpoint may be subject to rate limiting.
// @see https://docs.gemini.com/rest-api/#order-status
func (c *Client) GetOrderStatusWithTrades(orderID int) (resp OrderStatusResponseWithTrades, err error) {
order := OrderStatusRequestPayload{
OrderID: orderID,
IncludeTrades: true,
}
order.Nonce = c.createNonce()
order.Request = "/v1/order/status"
bodyBytes, err := json.Marshal(order)
if err != nil {
return
}
err = c.Call("POST", "/order/status", bodyBytes, &resp)
return
}
//GetActiveOrders Returns ALL active orders in Gemini.
//@see https://docs.gemini.com/rest-api/#get-active-orders
func (c *Client) GetActiveOrders() (resp []OrderStatusResponse, err error) {
body := BaseRequest{
Nonce: c.createNonce(),
Request: "/v1/orders",
}
bodyBytes, err := json.Marshal(body)
if err != nil {
return
}
err = c.Call("POST", "/orders", bodyBytes, &resp)
return
}
type (
GetPastTradesOptions struct {
Symbol string
LimitTrades int
Timestamp int64
Account string
}
GetPastTradesPayload struct {
BaseRequest
Symbol string `json:"symbol"`
LimitTrades int `json:"limit_trades,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
Account string `json:"account,omitempty"`
}
)
//GetPastTrades Returns all past trades made by user with supplied symbol
//@see https://docs.gemini.com/rest-api/#get-past-trades
func (c *Client) GetPastTrades(options GetPastTradesOptions) (resp []OrderStatusTrade, err error) {
body := GetPastTradesPayload{
Symbol: options.Symbol,
LimitTrades: options.LimitTrades,
Timestamp: options.Timestamp,
Account: options.Account,
}
body.Nonce = c.createNonce()
body.Request = "/v1/mytrades"
bodyBytes, err := json.Marshal(body)
if err != nil {
return
}
err = c.Call("POST", "/mytrades", bodyBytes, &resp)
return
}