forked from Kucoin/kucoin-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hf_order.go
333 lines (295 loc) · 12.6 KB
/
hf_order.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
package kucoin
import (
"encoding/json"
"math/big"
"net/http"
)
// HfPlaceOrder There are two types of orders:
// (limit) order: set price and quantity for the transaction.
// (market) order : set amount or quantity for the transaction.
func (as *ApiService) HfPlaceOrder(params map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/hf/orders", params)
return as.Call(req)
}
type HfPlaceOrderRes struct {
OrderId string `json:"orderId"`
Success bool `json:"success"`
}
// HfSyncPlaceOrder The difference between this interface
// and "Place hf order" is that this interface will synchronously
// return the order information after the order matching is completed.
// For higher latency requirements, please select the "Place hf order" interface.
// If there is a requirement for returning data integrity, please select this interface
func (as *ApiService) HfSyncPlaceOrder(params map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/hf/orders/sync", params)
return as.Call(req)
}
type HfSyncPlaceOrderRes struct {
OrderId string `json:"orderId"`
OrderTime json.Number `json:"orderTime"`
OriginSize string `json:"originSize"`
DealSize string `json:"dealSize"`
RemainSize string `json:"remainSize"`
CanceledSize string `json:"canceledSize"`
Status string `json:"status"`
MatchTime json.Number `json:"matchTime"`
}
// HfPlaceMultiOrders This endpoint supports sequential batch order placement from a single endpoint.
// A maximum of 5orders can be placed simultaneously.
// The order types must be limit orders of the same trading pair
// (this endpoint currently only supports spot trading and does not support margin trading)
func (as *ApiService) HfPlaceMultiOrders(orders []*HFCreateMultiOrderModel) (*ApiResponse, error) {
p := map[string]interface{}{
"orderList": orders,
}
req := NewRequest(http.MethodPost, "/api/v1/hf/orders/multi", p)
return as.Call(req)
}
type HFCreateMultiOrderModel struct {
ClientOid string `json:"clientOid"`
Symbol string `json:"symbol"`
OrderType string `json:"type"`
TimeInForce string `json:"timeInForce"`
Stp string `json:"stp"`
Side string `json:"side"`
Price string `json:"price"`
Size string `json:"size"`
CancelAfter big.Int `json:"cancelAfter"`
PostOnly bool `json:"postOnly"`
Hidden bool `json:"hidden"`
Iceberg bool `json:"iceberg"`
VisibleSize string `json:"visibleSize"`
Tags string `json:"tags"`
Remark string `json:"remark"`
}
type HfPlaceMultiOrdersRes []*HfPlaceOrderRes
// HfSyncPlaceMultiOrders The request parameters of this interface
// are the same as those of the "Sync place multiple hf orders" interface
// The difference between this interface and "Sync place multiple hf orders" is that
// this interface will synchronously return the order information after the order matching is completed.
func (as *ApiService) HfSyncPlaceMultiOrders(orders []*HFCreateMultiOrderModel) (*ApiResponse, error) {
p := map[string]interface{}{
"orderList": orders,
}
req := NewRequest(http.MethodPost, "/api/v1/hf/orders/multi/sync", p)
return as.Call(req)
}
type HfSyncPlaceMultiOrdersRes []*HfSyncPlaceOrderRes
// HfModifyOrder
// This interface can modify the price and quantity of the order according to orderId or clientOid.
func (as *ApiService) HfModifyOrder(params map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/hf/orders/alter", params)
return as.Call(req)
}
type HfModifyOrderRes struct {
NewOrderId string `json:"newOrderId"`
}
// HfCancelOrder This endpoint can be used to cancel a high-frequency order by orderId.
func (as *ApiService) HfCancelOrder(orderId, symbol string) (*ApiResponse, error) {
p := map[string]string{
"symbol": symbol,
}
req := NewRequest(http.MethodDelete, "/api/v1/hf/orders/"+orderId, p)
return as.Call(req)
}
// HfSyncCancelOrder The difference between this interface and "Cancel orders by orderId" is that
// this interface will synchronously return the order information after the order canceling is completed.
func (as *ApiService) HfSyncCancelOrder(orderId, symbol string) (*ApiResponse, error) {
p := map[string]string{
"symbol": symbol,
}
req := NewRequest(http.MethodDelete, "/api/v1/hf/orders/sync/"+orderId, p)
return as.Call(req)
}
type HfSyncCancelOrderRes struct {
OrderId string `json:"orderId"`
OriginSize string `json:"originSize"`
OriginFunds string `json:"originFunds"`
DealSize string `json:"dealSize"`
RemainSize string `json:"remainSize"`
CanceledSize string `json:"canceledSize"`
Status string `json:"status"`
}
// HfCancelOrderByClientId This endpoint sends out a request to cancel a high-frequency order using clientOid.
func (as *ApiService) HfCancelOrderByClientId(clientOid, symbol string) (*ApiResponse, error) {
p := map[string]string{
"symbol": symbol,
}
req := NewRequest(http.MethodDelete, "/api/v1/hf/orders/client-order/"+clientOid, p)
return as.Call(req)
}
// HfSyncCancelOrderByClientId The difference between this interface and "Cancellation of order by clientOid"
// is that this interface will synchronously return the order information after the order canceling is completed.
func (as *ApiService) HfSyncCancelOrderByClientId(clientOid, symbol string) (*ApiResponse, error) {
p := map[string]string{
"symbol": symbol,
}
req := NewRequest(http.MethodDelete, "/api/v1/hf/orders/sync/client-order/"+clientOid, p)
return as.Call(req)
}
// HfSyncCancelOrderWithSize This interface can cancel the specified quantity of the order according to the orderId.
func (as *ApiService) HfSyncCancelOrderWithSize(orderId, symbol, cancelSize string) (*ApiResponse, error) {
p := map[string]string{
"symbol": symbol,
"cancelSize": cancelSize,
}
req := NewRequest(http.MethodDelete, "/api/v1/hf/orders/cancel/"+orderId, p)
return as.Call(req)
}
type HfSyncCancelOrderWithSizeRes struct {
OrderId string `json:"orderId"`
CancelSize string `json:"cancelSize"`
}
// HfSyncCancelAllOrders his endpoint allows cancellation of all orders related to a specific trading pair
// with a status of open
// (including all orders pertaining to high-frequency trading accounts and non-high-frequency trading accounts)
func (as *ApiService) HfSyncCancelAllOrders(symbol string) (*ApiResponse, error) {
p := map[string]string{
"symbol": symbol,
}
req := NewRequest(http.MethodDelete, "/api/v1/hf/orders", p)
return as.Call(req)
}
// HfObtainActiveOrders This endpoint obtains a list of all active HF orders.
// The return data is sorted in descending order based on the latest update times.
func (as *ApiService) HfObtainActiveOrders(symbol string) (*ApiResponse, error) {
p := map[string]string{
"symbol": symbol,
}
req := NewRequest(http.MethodGet, "/api/v1/hf/orders/active", p)
return as.Call(req)
}
type HfOrdersModel []*HfOrderModel
type HfOrderModel struct {
Id string `json:"id"`
Symbol string `json:"symbol"`
OpType string `json:"opType"`
Type string `json:"type"`
Side string `json:"side"`
Price string `json:"price"`
Size string `json:"size"`
Funds string `json:"funds"`
DealSize string `json:"dealSize"`
DealFunds string `json:"dealFunds"`
Fee string `json:"fee"`
FeeCurrency string `json:"feeCurrency"`
Stp string `json:"stp"`
TimeInForce string `json:"timeInForce"`
PostOnly bool `json:"postOnly"`
Hidden bool `json:"hidden"`
Iceberg bool `json:"iceberg"`
VisibleSize string `json:"visibleSize"`
CancelAfter int64 `json:"cancelAfter"`
Channel string `json:"channel"`
ClientOid string `json:"clientOid"`
Remark string `json:"remark"`
Tags string `json:"tags"`
CancelExist bool `json:"cancelExist"`
CreatedAt json.Number `json:"createdAt"`
LastUpdatedAt json.Number `json:"lastUpdatedAt"`
TradeType string `json:"tradeType"`
InOrderBook bool `json:"inOrderBook"`
Active bool `json:"active"`
CancelledSize string `json:"cancelledSize"`
CancelledFunds string `json:"cancelledFunds"`
RemainSize string `json:"remainSize"`
RemainFunds string `json:"remainFunds"`
}
// HfObtainActiveSymbols This interface can query all trading pairs that the user has active orders
func (as *ApiService) HfObtainActiveSymbols() (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/hf/orders/active/symbols", nil)
return as.Call(req)
}
type HfSymbolsModel struct {
Symbols []string `json:"symbols"`
}
// HfObtainFilledOrders This endpoint obtains a list of filled HF orders and returns paginated data.
// The returned data is sorted in descending order based on the latest order update times.
func (as *ApiService) HfObtainFilledOrders(p map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/hf/orders/done", p)
return as.Call(req)
}
type HfFilledOrdersModel struct {
LastId json.Number `json:"lastId"`
Items []*HfOrderModel `json:"items"`
}
// HfOrderDetail This endpoint can be used to obtain information for a single HF order using the order id.
func (as *ApiService) HfOrderDetail(orderId, symbol string) (*ApiResponse, error) {
p := map[string]string{
"symbol": symbol,
}
req := NewRequest(http.MethodGet, "/api/v1/hf/orders/"+orderId, p)
return as.Call(req)
}
// HfOrderDetailByClientOid The endpoint can be used to obtain information about a single order using clientOid.
// If the order does not exist, then there will be a prompt saying that the order does not exist.
func (as *ApiService) HfOrderDetailByClientOid(clientOid, symbol string) (*ApiResponse, error) {
p := map[string]string{
"symbol": symbol,
}
req := NewRequest(http.MethodGet, "/api/v1/hf/orders/client-order/"+clientOid, p)
return as.Call(req)
}
// HfAutoCancelSetting automatically cancel all orders of the set trading pair after the specified time.
// If this interface is not called again for renewal or cancellation before the set time,
// the system will help the user to cancel the order of the corresponding trading pair.
// otherwise it will not.
func (as *ApiService) HfAutoCancelSetting(timeout int64, symbol string) (*ApiResponse, error) {
p := map[string]interface{}{
"symbol": symbol,
"timeout": timeout,
}
req := NewRequest(http.MethodPost, "/api/v1/hf/orders/dead-cancel-all", p)
return as.Call(req)
}
type HfAutoCancelSettingRes struct {
CurrentTime json.Number `json:"currentTime"`
TriggerTime json.Number `json:"triggerTime"`
}
// HfQueryAutoCancelSetting Through this interface, you can query the settings of automatic order cancellation
func (as *ApiService) HfQueryAutoCancelSetting() (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/hf/orders/dead-cancel-all/query", nil)
return as.Call(req)
}
type AUtoCancelSettingModel struct {
Timeout int64 `json:"timeout"`
Symbols string `json:"symbols"`
CurrentTime json.Number `json:"currentTime"`
TriggerTime json.Number `json:"triggerTime"`
}
type HfOrderIdModel struct {
OrderId string `json:"orderId"`
}
type HfClientOidModel struct {
ClientOid string `json:"clientOid"`
}
// HfTransactionDetails This endpoint can be used to obtain a list of the latest HF transaction details.
// The returned results are paginated. The data is sorted in descending order according to time.
func (as *ApiService) HfTransactionDetails(p map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/hf/fills", p)
return as.Call(req)
}
type HfTransactionDetailsModel struct {
LastId json.Number `json:"lastId"`
Items []*HfTransactionDetailModel `json:"items"`
}
type HfTransactionDetailModel struct {
Id json.Number `json:"id"`
Symbol string `json:"symbol"`
TradeId json.Number `json:"tradeId"`
OrderId string `json:"orderId"`
CounterOrderId string `json:"counterOrderId"`
Side string `json:"side"`
Liquidity string `json:"liquidity"`
ForceTaker bool `json:"forceTaker"`
Price string `json:"price"`
Size string `json:"size"`
Funds string `json:"funds"`
Fee string `json:"fee"`
FeeRate string `json:"feeRate"`
FeeCurrency string `json:"feeCurrency"`
OrderType string `json:"type"`
Stop string `json:"stop"`
CreatedAt json.Number `json:"createdAt"`
TradeType string `json:"tradeType"`
}