This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
/
order.go
388 lines (336 loc) · 14.3 KB
/
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
package kucoin
import (
"context"
"net/http"
)
// A CreateOrderModel is the input parameter of CreateOrder().
type CreateOrderModel struct {
// BASE PARAMETERS
ClientOid string `json:"clientOid"`
Side string `json:"side"`
Symbol string `json:"symbol,omitempty"`
Type string `json:"type,omitempty"`
Remark string `json:"remark,omitempty"`
Stop string `json:"stop,omitempty"`
StopPrice string `json:"stopPrice,omitempty"`
STP string `json:"stp,omitempty"`
TradeType string `json:"tradeType,omitempty"`
// LIMIT ORDER PARAMETERS
Price string `json:"price,omitempty"`
Size string `json:"size,omitempty"`
TimeInForce string `json:"timeInForce,omitempty"`
CancelAfter int64 `json:"cancelAfter,omitempty"`
PostOnly bool `json:"postOnly,omitempty"`
Hidden bool `json:"hidden,omitempty"`
IceBerg bool `json:"iceberg,omitempty"`
VisibleSize string `json:"visibleSize,omitempty"`
// MARKET ORDER PARAMETERS
// Size string `json:"size"`
Funds string `json:"funds,omitempty"`
// MARGIN ORDER PARAMETERS
MarginMode string `json:"marginMode,omitempty"`
AutoBorrow bool `json:"autoBorrow,omitempty"`
AutoRepay bool `json:"autoRepay,omitempty"`
}
// A CreateOrderResultModel represents the result of CreateOrder().
type CreateOrderResultModel struct {
OrderId string `json:"orderId"`
}
// CreateOrder places a new order.
func (as *ApiService) CreateOrder(ctx context.Context, o *CreateOrderModel) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/orders", o)
return as.Call(ctx, req)
}
// CreateOrderTest places a new order test.
func (as *ApiService) CreateOrderTest(ctx context.Context, o *CreateOrderModel) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/orders/test", o)
return as.Call(ctx, req)
}
// A CreateMultiOrderResultModel represents the result of CreateMultiOrder().
type CreateMultiOrderResultModel struct {
Data OrdersModel `json:"data"`
}
// CreateMultiOrder places bulk orders.
func (as *ApiService) CreateMultiOrder(ctx context.Context, symbol string, orders []*CreateOrderModel) (*ApiResponse, error) {
params := map[string]interface{}{
"symbol": symbol,
"orderList": orders,
}
req := NewRequest(http.MethodPost, "/api/v1/orders/multi", params)
return as.Call(ctx, req)
}
// A CancelOrderResultModel represents the result of CancelOrder().
type CancelOrderResultModel struct {
CancelledOrderIds []string `json:"cancelledOrderIds"`
}
// CancelOrder cancels a previously placed order.
func (as *ApiService) CancelOrder(ctx context.Context, orderId string) (*ApiResponse, error) {
req := NewRequest(http.MethodDelete, "/api/v1/orders/"+orderId, nil)
return as.Call(ctx, req)
}
// A CancelOrderByClientResultModel represents the result of CancelOrderByClient().
type CancelOrderByClientResultModel struct {
CancelledOrderId string `json:"cancelledOrderId"`
ClientOid string `json:"clientOid"`
}
// CancelOrderByClient cancels a previously placed order by client ID.
func (as *ApiService) CancelOrderByClient(ctx context.Context, clientOid string) (*ApiResponse, error) {
req := NewRequest(http.MethodDelete, "/api/v1/order/client-order/"+clientOid, nil)
return as.Call(ctx, req)
}
// CancelOrders cancels all orders of the symbol.
// With best effort, cancel all open orders. The response is a list of ids of the canceled orders.
func (as *ApiService) CancelOrders(ctx context.Context, p map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodDelete, "/api/v1/orders", p)
return as.Call(ctx, req)
}
// An OrderModel represents an order.
type OrderModel 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"`
DealFunds string `json:"dealFunds"`
DealSize string `json:"dealSize"`
Fee string `json:"fee"`
FeeCurrency string `json:"feeCurrency"`
Stp string `json:"stp"`
Stop string `json:"stop"`
StopTriggered bool `json:"stopTriggered"`
StopPrice string `json:"stopPrice"`
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"`
IsActive bool `json:"isActive"`
CancelExist bool `json:"cancelExist"`
CreatedAt int64 `json:"createdAt"`
TradeType string `json:"tradeType"`
}
// A OrdersModel is the set of *OrderModel.
type OrdersModel []*OrderModel
// Orders returns a list your current orders.
func (as *ApiService) Orders(ctx context.Context, params map[string]string, pagination *PaginationParam) (*ApiResponse, error) {
pagination.ReadParam(params)
req := NewRequest(http.MethodGet, "/api/v1/orders", params)
return as.Call(ctx, req)
}
// A V1OrderModel represents a v1 order.
type V1OrderModel struct {
Symbol string `json:"symbol"`
DealPrice string `json:"dealPrice"`
DealValue string `json:"dealValue"`
Amount string `json:"amount"`
Fee string `json:"fee"`
Side string `json:"side"`
CreatedAt int64 `json:"createdAt"`
}
// A V1OrdersModel is the set of *V1OrderModel.
type V1OrdersModel []*V1OrderModel
// V1Orders returns a list of v1 historical orders.
// Deprecated
func (as *ApiService) V1Orders(ctx context.Context, params map[string]string, pagination *PaginationParam) (*ApiResponse, error) {
pagination.ReadParam(params)
req := NewRequest(http.MethodGet, "/api/v1/hist-orders", params)
return as.Call(ctx, req)
}
// Order returns a single order by order id.
func (as *ApiService) Order(ctx context.Context, orderId string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/orders/"+orderId, nil)
return as.Call(ctx, req)
}
// OrderByClient returns a single order by client id.
func (as *ApiService) OrderByClient(ctx context.Context, clientOid string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/order/client-order/"+clientOid, nil)
return as.Call(ctx, req)
}
// RecentOrders returns the recent orders of the latest transactions within 24 hours.
func (as *ApiService) RecentOrders(ctx context.Context) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/limit/orders", nil)
return as.Call(ctx, req)
}
// CreateStopOrder places a new stop-order.
func (as *ApiService) CreateStopOrder(ctx context.Context, o *CreateOrderModel) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/stop-order", o)
return as.Call(ctx, req)
}
// CancelStopOrder cancels a previously placed stop-order.
func (as *ApiService) CancelStopOrder(ctx context.Context, orderId string) (*ApiResponse, error) {
req := NewRequest(http.MethodDelete, "/api/v1/stop-order/"+orderId, nil)
return as.Call(ctx, req)
}
// CancelStopOrderByClientModel returns Model of CancelStopOrderByClient API
type CancelStopOrderByClientModel struct {
CancelledOrderId string `json:"cancelledOrderId"`
ClientOid string `json:"clientOid"`
}
// CancelStopOrderByClient cancels a previously placed stop-order by client ID.
func (as *ApiService) CancelStopOrderByClient(ctx context.Context, clientOid string, p map[string]string) (*ApiResponse, error) {
p["clientOid"] = clientOid
req := NewRequest(http.MethodDelete, "/api/v1/stop-order/cancelOrderByClientOid", p)
return as.Call(ctx, req)
}
// StopOrderModel RESPONSES of StopOrder
type StopOrderModel struct {
Id string `json:"id"`
Symbol string `json:"symbol"`
UserId string `json:"userId"`
Status string `json:"status"`
Type string `json:"type"`
Side string `json:"side"`
Price string `json:"price"`
Size string `json:"size"`
Funds string `json:"funds"`
Stp string `json:"stp"`
TimeInForce string `json:"timeInForce"`
CancelAfter int64 `json:"cancelAfter"`
PostOnly bool `json:"postOnly"`
Hidden bool `json:"hidden"`
IceBerg bool `json:"iceberg"`
VisibleSize string `json:"visibleSize"`
Channel string `json:"channel"`
ClientOid string `json:"clientOid"`
Remark string `json:"remark"`
Tags string `json:"tags"`
OrderTime int64 `json:"orderTime"`
DomainId string `json:"domainId"`
TradeSource string `json:"tradeSource"`
TradeType string `json:"tradeType"`
FeeCurrency string `json:"feeCurrency"`
TakerFeeRate string `json:"takerFeeRate"`
MakerFeeRate string `json:"makerFeeRate"`
CreatedAt int64 `json:"createdAt"`
Stop string `json:"stop"`
StopTriggerTime string `json:"stopTriggerTime"`
StopPrice string `json:"stopPrice"`
}
// StopOrder returns a single order by stop-order id.
func (as *ApiService) StopOrder(ctx context.Context, orderId string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v1/stop-order/"+orderId, nil)
return as.Call(ctx, req)
}
// StopOrderListModel StopOrderByClient model
type StopOrderListModel []*StopOrderModel
// StopOrderByClient returns a single stop-order by client id.
func (as *ApiService) StopOrderByClient(ctx context.Context, clientOid string, p map[string]string) (*ApiResponse, error) {
p["clientOid"] = clientOid
req := NewRequest(http.MethodGet, "/api/v1/stop-order/queryOrderByClientOid", p)
return as.Call(ctx, req)
}
// StopOrders returns a list your current orders.
func (as *ApiService) StopOrders(ctx context.Context, params map[string]string, pagination *PaginationParam) (*ApiResponse, error) {
pagination.ReadParam(params)
req := NewRequest(http.MethodGet, "/api/v1/stop-order", params)
return as.Call(ctx, req)
}
// CancelStopOrderBy returns a list your current orders.
func (as *ApiService) CancelStopOrderBy(ctx context.Context, params map[string]string) (*ApiResponse, error) {
req := NewRequest(http.MethodDelete, "/api/v1/stop-order/cancel", params)
return as.Call(ctx, req)
}
// CreateMarginOrder places a new margin order.
func (as *ApiService) CreateMarginOrder(ctx context.Context, o *CreateOrderModel) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/margin/order", o)
return as.Call(ctx, req)
}
// CreateMarginOrderTest places a new margin test order.
func (as *ApiService) CreateMarginOrderTest(ctx context.Context, o *CreateOrderModel) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v1/margin/order/test", o)
return as.Call(ctx, req)
}
// A CreateOcoOrderModel is the input parameter of CreatOcoOrder().
type CreateOcoOrderModel struct {
Side string `json:"side"`
Symbol string `json:"symbol,omitempty"`
Price string `json:"price,omitempty"`
Size string `json:"size,omitempty"`
StopPrice string `json:"stopPrice,omitempty"`
LimitPrice string `json:"limitPrice,omitempty"`
TradeType string `json:"tradeType"`
ClientOid string `json:"clientOid,omitempty"`
Remark string `json:"remark"`
}
// CreateOcoOrder places a new margin order.
func (as *ApiService) CreateOcoOrder(ctx context.Context, o *CreateOcoOrderModel) (*ApiResponse, error) {
req := NewRequest(http.MethodPost, "/api/v3/oco/order", o)
return as.Call(ctx, req)
}
type CancelledOcoOrderResModel struct {
CancelledOrderIds []string `json:"cancelledOrderIds"`
}
// DeleteOcoOrder cancel a oco order. return CancelledOcoOrderResModel
func (as *ApiService) DeleteOcoOrder(ctx context.Context, orderId string) (*ApiResponse, error) {
req := NewRequest(http.MethodDelete, "/api/v3/oco/order/"+orderId, nil)
return as.Call(ctx, req)
}
// DeleteOcoOrderClientId cancel a oco order with clientOrderId. return CancelledOcoOrderResModel
func (as *ApiService) DeleteOcoOrderClientId(ctx context.Context, clientOrderId string) (*ApiResponse, error) {
req := NewRequest(http.MethodDelete, "/api/v3/oco/client-order/"+clientOrderId, nil)
return as.Call(ctx, req)
}
// DeleteOcoOrders cancel all oco order. return CancelledOcoOrderResModel
func (as *ApiService) DeleteOcoOrders(ctx context.Context, symbol, orderIds string) (*ApiResponse, error) {
params := map[string]interface{}{
"symbol": symbol,
"orderIds": orderIds,
}
req := NewRequest(http.MethodDelete, "/api/v3/oco/orders", params)
return as.Call(ctx, req)
}
type OcoOrderResModel struct {
OrderId string `json:"order_id"`
Symbol string `json:"symbol"`
ClientOid string `json:"clientOid"`
OrderTime int64 `json:"orderTime"`
Status string `json:"status"`
}
// OcoOrder returns a oco order by order id. return OcoOrderResModel
func (as *ApiService) OcoOrder(ctx context.Context, orderId string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v3/oco/order/"+orderId, nil)
return as.Call(ctx, req)
}
// OcoClientOrder returns a oco order by order id. return OcoOrderResModel
func (as *ApiService) OcoClientOrder(ctx context.Context, clientOrderId string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v3/oco/client-order/"+clientOrderId, nil)
return as.Call(ctx, req)
}
type OcoOrdersRes []*OcoOrderResModel
// OcoOrders returns a oco order by order id. return OcoOrdersRes
func (as *ApiService) OcoOrders(ctx context.Context, p map[string]string, pagination *PaginationParam) (*ApiResponse, error) {
pagination.ReadParam(p)
req := NewRequest(http.MethodGet, "/api/v3/oco/orders", p)
return as.Call(ctx, req)
}
type OcoOrdersModel []*OrderDetailModel
type OrderDetailModel struct {
OrderId string `json:"order_id"`
Symbol string `json:"symbol"`
ClientOid string `json:"clientOid"`
OrderTime int64 `json:"orderTime"`
Status string `json:"status"`
Orders []*OcoSubOrderModel `json:"orders"`
}
type OcoSubOrderModel struct {
Id string `json:"id"`
Symbol string `json:"symbol"`
Side string `json:"side"`
Price string `json:"price"`
StopPrice string `json:"stopPrice"`
Size string `json:"size"`
Status string `json:"status"`
}
// OcoOrderDetail returns a oco order detail by order id. return OrderDetailModel
func (as *ApiService) OcoOrderDetail(ctx context.Context, orderId string) (*ApiResponse, error) {
req := NewRequest(http.MethodGet, "/api/v3/oco/order/details/"+orderId, nil)
return as.Call(ctx, req)
}