0
# Spot Trading
1
2
Complete spot trading functionality for KuCoin exchange including order placement, cancellation, management, and trade history. Supports standard orders, stop orders, high-frequency trading, and OCO (One-Cancels-Other) orders.
3
4
## Capabilities
5
6
### Basic Order Management
7
8
Standard limit and market order operations.
9
10
```python { .api }
11
def create_limit_order(symbol: str, side: str, size: str, price: str, clientOid: str = '', **kwargs):
12
"""
13
Place a limit order.
14
15
Args:
16
symbol (str): Trading symbol (e.g., 'BTC-USDT')
17
side (str): Order side ('buy' or 'sell')
18
size (str): Order size (base currency amount)
19
price (str): Order price
20
clientOid (str, optional): Client order ID (UUID recommended)
21
timeInForce (str, optional): Time in force ('GTC', 'GTT', 'IOC', 'FOK')
22
cancelAfter (int, optional): Cancel after seconds (requires GTT)
23
postOnly (bool, optional): Post-only flag
24
hidden (bool, optional): Hidden order flag
25
iceberg (bool, optional): Iceberg order flag
26
visibleSize (str, optional): Visible size for iceberg orders
27
remark (str, optional): Order remark
28
29
Returns:
30
dict: Order response with orderId
31
"""
32
33
def create_market_order(symbol: str, side: str, clientOid: str = '', size: str = None, funds: str = None, **kwargs):
34
"""
35
Place a market order.
36
37
Args:
38
symbol (str): Trading symbol
39
side (str): Order side ('buy' or 'sell')
40
clientOid (str, optional): Client order ID
41
size (str, optional): Order size (required for sell orders)
42
funds (str, optional): Order funds (required for buy orders)
43
**kwargs: Additional order parameters
44
45
Returns:
46
dict: Order response with orderId
47
"""
48
49
def cancel_order(orderId: str):
50
"""
51
Cancel an order by order ID.
52
53
Args:
54
orderId (str): Order ID to cancel
55
56
Returns:
57
dict: Cancellation response with cancelledOrderIds
58
"""
59
60
def cancel_client_order(clientId: str):
61
"""
62
Cancel an order by client order ID.
63
64
Args:
65
clientId (str): Client order ID to cancel
66
67
Returns:
68
dict: Cancellation response
69
"""
70
71
def cancel_all_orders(**kwargs):
72
"""
73
Cancel all orders.
74
75
Args:
76
symbol (str, optional): Limit to specific symbol
77
tradeType (str, optional): Trade type filter
78
79
Returns:
80
dict: List of cancelled order IDs
81
"""
82
83
def place_order_test(symbol: str, side: str, type: str, clientOid: str = '', **kwargs):
84
"""
85
Test order placement without actually placing the order.
86
87
Args:
88
symbol (str): Trading symbol
89
side (str): Order side
90
type (str): Order type ('limit' or 'market')
91
clientOid (str, optional): Client order ID
92
**kwargs: Order parameters based on type
93
94
Returns:
95
dict: Test result with order validation
96
"""
97
```
98
99
### Stop Orders
100
101
Stop-loss and take-profit order functionality.
102
103
```python { .api }
104
def create_limit_stop_order(symbol: str, side: str, size: str, price: str, stopPrice: str, clientOid: str = '', **kwargs):
105
"""
106
Place a limit stop order.
107
108
Args:
109
symbol (str): Trading symbol
110
side (str): Order side
111
size (str): Order size
112
price (str): Limit price
113
stopPrice (str): Stop trigger price
114
clientOid (str, optional): Client order ID
115
**kwargs: Additional parameters
116
117
Returns:
118
dict: Stop order response
119
"""
120
121
def create_market_stop_order(symbol: str, side: str, stopPrice: str, size: str = '', funds: str = '', clientOid: str = '', **kwargs):
122
"""
123
Place a market stop order.
124
125
Args:
126
symbol (str): Trading symbol
127
side (str): Order side
128
stopPrice (str): Stop trigger price
129
size (str, optional): Order size (for sell orders)
130
funds (str, optional): Order funds (for buy orders)
131
clientOid (str, optional): Client order ID
132
133
Returns:
134
dict: Stop order response
135
"""
136
137
def cancel_stop_order(orderId: str):
138
"""
139
Cancel a stop order.
140
141
Args:
142
orderId (str): Stop order ID
143
144
Returns:
145
dict: Cancellation response
146
"""
147
148
def cancel_client_stop_order(clientOid: str, symbol: str = ''):
149
"""
150
Cancel a stop order by client order ID.
151
152
Args:
153
clientOid (str): Client order ID
154
symbol (str, optional): Trading symbol
155
156
Returns:
157
dict: Cancellation response
158
"""
159
160
def get_all_stop_order_details(**kwargs):
161
"""
162
Get all stop order details.
163
164
Args:
165
symbol (str, optional): Filter by symbol
166
side (str, optional): Filter by side
167
type (str, optional): Filter by order type
168
**kwargs: Additional filters
169
170
Returns:
171
dict: Stop order list with pagination
172
"""
173
```
174
175
### High-Frequency Trading
176
177
Specialized high-frequency trading operations with enhanced performance.
178
179
```python { .api }
180
def create_limit_hf_order(symbol: str, side: str, size: str, price: str, clientOid: str = '', **kwargs):
181
"""
182
Place a high-frequency limit order.
183
184
Args:
185
symbol (str): Trading symbol
186
side (str): Order side
187
size (str): Order size
188
price (str): Order price
189
clientOid (str, optional): Client order ID
190
**kwargs: Additional HF order parameters
191
192
Returns:
193
dict: HF order response
194
"""
195
196
def sync_create_limit_hf_order(symbol: str, side: str, size: str, price: str, clientOid: str = '', **kwargs):
197
"""
198
Place a synchronous high-frequency limit order.
199
200
Args:
201
symbol (str): Trading symbol
202
side (str): Order side
203
size (str): Order size
204
price (str): Order price
205
clientOid (str, optional): Client order ID
206
207
Returns:
208
dict: Synchronous order response with execution details
209
"""
210
211
def cancel_all_hf_orders(symbol: str):
212
"""
213
Cancel all high-frequency orders for a symbol.
214
215
Args:
216
symbol (str): Trading symbol
217
218
Returns:
219
str: Success message
220
"""
221
222
def get_active_hf_orders(symbol: str):
223
"""
224
Get active high-frequency orders.
225
226
Args:
227
symbol (str): Trading symbol
228
229
Returns:
230
list: Active HF orders
231
"""
232
```
233
234
### OCO Orders
235
236
One-Cancels-Other order functionality for advanced trading strategies.
237
238
```python { .api }
239
def create_oco_order(symbol: str, side: str, price: str, stopPrice: str, size: str, limitPrice: str, clientOid: str = '', remark: str = None):
240
"""
241
Place an OCO (One-Cancels-Other) order.
242
243
Args:
244
symbol (str): Trading symbol
245
side (str): Order side
246
price (str): Main order price
247
stopPrice (str): Stop order trigger price
248
size (str): Order size
249
limitPrice (str): Stop order limit price
250
clientOid (str, optional): Client order ID
251
remark (str, optional): Order remark
252
253
Returns:
254
dict: OCO order response
255
"""
256
257
def cancel_oco_order(orderId: str):
258
"""
259
Cancel an OCO order by order ID.
260
261
Args:
262
orderId (str): OCO order ID
263
264
Returns:
265
dict: List of cancelled order IDs
266
"""
267
268
def get_oco_orders(pageSize: int, currentPage: int, symbol: str = None, **kwargs):
269
"""
270
Get OCO order list.
271
272
Args:
273
pageSize (int): Page size (10-500)
274
currentPage (int): Page number (min 1)
275
symbol (str, optional): Filter by symbol
276
startAt (int, optional): Start time
277
endAt (int, optional): End time
278
orderIds (str, optional): Comma-separated order IDs
279
280
Returns:
281
dict: Paginated OCO orders
282
"""
283
```
284
285
### Order Information
286
287
Retrieve order details and trading history.
288
289
```python { .api }
290
def get_order_list(**kwargs):
291
"""
292
Get order list with filtering.
293
294
Args:
295
status (str, optional): Order status ('active', 'done')
296
symbol (str, optional): Trading symbol
297
side (str, optional): Order side
298
type (str, optional): Order type
299
tradeType (str, optional): Trade type
300
startAt (int, optional): Start time
301
endAt (int, optional): End time
302
currentPage (int, optional): Page number
303
pageSize (int, optional): Page size
304
305
Returns:
306
dict: Paginated order list
307
"""
308
309
def get_order_details(orderId: str):
310
"""
311
Get detailed information for a specific order.
312
313
Args:
314
orderId (str): Order ID
315
316
Returns:
317
dict: Complete order information
318
"""
319
320
def get_recent_orders():
321
"""
322
Get recent orders (last 24 hours).
323
324
Returns:
325
dict: Recent orders list
326
"""
327
```
328
329
### Trade History
330
331
Access to fill history and trade records.
332
333
```python { .api }
334
def get_fill_list(tradeType: str, **kwargs):
335
"""
336
Get fill (trade execution) history.
337
338
Args:
339
tradeType (str): Trade type ('TRADE', 'MARGIN_TRADE')
340
orderId (str, optional): Filter by order ID
341
symbol (str, optional): Filter by symbol
342
side (str, optional): Filter by side
343
type (str, optional): Filter by order type
344
startAt (int, optional): Start time
345
endAt (int, optional): End time
346
currentPage (int, optional): Page number
347
pageSize (int, optional): Page size
348
349
Returns:
350
dict: Paginated fill history
351
"""
352
353
def get_recent_fills():
354
"""
355
Get recent fills (last 24 hours).
356
357
Returns:
358
list: Recent fill records
359
"""
360
```
361
362
### Bulk Operations
363
364
Efficient bulk order operations.
365
366
```python { .api }
367
def create_bulk_orders(symbol: str, orderList: list):
368
"""
369
Place multiple orders in a single request.
370
371
Args:
372
symbol (str): Trading symbol
373
orderList (list): List of order objects
374
375
Returns:
376
dict: Bulk order response with individual results
377
"""
378
379
def multi_create_hf_order(orderList: list):
380
"""
381
Place multiple high-frequency orders.
382
383
Args:
384
orderList (list): List of HF order objects
385
386
Returns:
387
list: Individual order responses
388
"""
389
```
390
391
## Usage Examples
392
393
### Basic Trading
394
395
```python
396
from kucoin.client import Trade
397
398
# Initialize trading client with authentication
399
trade = Trade(api_key, api_secret, api_passphrase, is_sandbox=False)
400
401
# Place a limit buy order
402
order = trade.create_limit_order(
403
symbol='BTC-USDT',
404
side='buy',
405
size='0.001',
406
price='30000',
407
timeInForce='GTC'
408
)
409
print(f"Order placed: {order['orderId']}")
410
411
# Check order status
412
order_details = trade.get_order_details(order['orderId'])
413
print(f"Order status: {order_details['isActive']}")
414
415
# Cancel the order if still active
416
if order_details['isActive']:
417
cancel_result = trade.cancel_order(order['orderId'])
418
print(f"Order cancelled: {cancel_result}")
419
```
420
421
### Market Orders
422
423
```python
424
# Place a market buy order using funds
425
market_order = trade.create_market_order(
426
symbol='BTC-USDT',
427
side='buy',
428
funds='100' # $100 worth of BTC
429
)
430
431
# Place a market sell order using size
432
market_sell = trade.create_market_order(
433
symbol='BTC-USDT',
434
side='sell',
435
size='0.001' # Sell 0.001 BTC
436
)
437
```
438
439
### Stop Orders
440
441
```python
442
# Place a stop-loss order
443
stop_loss = trade.create_market_stop_order(
444
symbol='BTC-USDT',
445
side='sell',
446
stopPrice='29000', # Trigger when price hits $29,000
447
size='0.001'
448
)
449
450
# Place a take-profit limit order
451
take_profit = trade.create_limit_stop_order(
452
symbol='BTC-USDT',
453
side='sell',
454
size='0.001',
455
price='35000', # Sell at $35,000
456
stopPrice='34900' # Trigger when price hits $34,900
457
)
458
```
459
460
### OCO Orders
461
462
```python
463
# Place an OCO order (take-profit and stop-loss)
464
oco_order = trade.create_oco_order(
465
symbol='BTC-USDT',
466
side='sell',
467
price='35000', # Take-profit price
468
stopPrice='29000', # Stop-loss trigger
469
size='0.001',
470
limitPrice='28900' # Stop-loss limit price
471
)
472
```
473
474
## Types
475
476
```python { .api }
477
OrderResponse = dict
478
# {
479
# "orderId": str # Unique order identifier
480
# }
481
482
OrderInfo = dict
483
# {
484
# "id": str, # Order ID
485
# "symbol": str, # Trading symbol
486
# "type": str, # Order type
487
# "side": str, # Order side
488
# "price": str, # Order price
489
# "size": str, # Order size
490
# "funds": str, # Order funds
491
# "dealFunds": str, # Executed funds
492
# "dealSize": str, # Executed size
493
# "fee": str, # Trading fee
494
# "feeCurrency": str, # Fee currency
495
# "timeInForce": str, # Time in force
496
# "postOnly": bool, # Post-only flag
497
# "hidden": bool, # Hidden order flag
498
# "iceberg": bool, # Iceberg order flag
499
# "visibleSize": str, # Visible size
500
# "cancelAfter": int, # Cancel after seconds
501
# "channel": str, # Order source
502
# "clientOid": str, # Client order ID
503
# "remark": str, # Order remark
504
# "isActive": bool, # Order active status
505
# "cancelExist": bool, # Cancel record exists
506
# "createdAt": int, # Creation timestamp
507
# "tradeType": str # Trade type
508
# }
509
510
FillInfo = dict
511
# {
512
# "symbol": str, # Trading symbol
513
# "tradeId": str, # Trade ID
514
# "orderId": str, # Order ID
515
# "counterOrderId": str, # Counter-party order ID
516
# "side": str, # Trade side
517
# "liquidity": str, # Liquidity type ('taker' or 'maker')
518
# "forceTaker": bool, # Forced taker flag
519
# "price": str, # Fill price
520
# "size": str, # Fill size
521
# "funds": str, # Fill funds
522
# "fee": str, # Trading fee
523
# "feeRate": str, # Fee rate
524
# "feeCurrency": str, # Fee currency
525
# "stop": str, # Stop type
526
# "type": str, # Order type
527
# "createdAt": int, # Fill timestamp
528
# "tradeType": str # Trade type
529
# }
530
531
BulkOrderItem = dict
532
# {
533
# "clientOid": str, # Client order ID
534
# "side": str, # Order side
535
# "type": str, # Order type
536
# "price": str, # Order price (for limit orders)
537
# "size": str, # Order size
538
# "timeInForce": str, # Time in force
539
# "cancelAfter": int, # Cancel after seconds
540
# "postOnly": bool, # Post-only flag
541
# "hidden": bool, # Hidden order flag
542
# "iceberg": bool, # Iceberg order flag
543
# "visibleSize": str # Visible size for iceberg
544
# }
545
```