Trading Endpoints
- class kucoin.client.Client(api_key=None, api_secret=None, passphrase=None, sandbox=False, requests_params=None)[source]
- cancel_all_orders(symbol=None, trade_type=None, **params)[source]
Cancel all orders
https://www.kucoin.com/docs/rest/spot-trading/orders/cancel-all-orders
- Parameters:
symbol (string) – (optional) Name of symbol e.g. ETH-USDT
trade_type (string) – (optional) The type of trading: TRADE - spot trading, MARGIN_TRADE - cross margin trading, MARGIN_ISOLATED_TRADE - isolated margin trading default is TRADE
res = client.cancel_all_orders()
- Returns:
ApiResponse
{ "cancelledOrderIds": [ "5bd6e9286d99522a52e458de" ] }
- Raises:
KucoinResponseException, KucoinAPIException
- cancel_order(order_id, **params)[source]
Cancel a spot order
https://www.kucoin.com/docs/rest/spot-trading/orders/cancel-order-by-orderid
- Parameters:
order_id (string) – Order id
res = client.cancel_order('5bd6e9286d99522a52e458de')
- Returns:
ApiResponse
{ "cancelledOrderIds": [ "5bd6e9286d99522a52e458de" ] }
- Raises:
KucoinResponseException, KucoinAPIException
KucoinAPIException If order_id is not found
- cancel_order_by_client_oid(client_oid, **params)[source]
Cancel a spot order by the clientOid
https://www.kucoin.com/docs/rest/spot-trading/orders/cancel-order-by-clientoid
- Parameters:
client_oid (string) – ClientOid
res = client.cancel_order_by_client_oid('6d539dc614db3')
- Returns:
ApiResponse
{ "cancelledOrderId": "5f311183c9b6d539dc614db3", "clientOid": "6d539dc614db3" }
- Raises:
KucoinResponseException, KucoinAPIException
KucoinAPIException If order_id is not found
- create_limit_order(symbol, side, price, size, client_oid=None, remark=None, time_in_force=None, stop=None, stop_price=None, stp=None, trade_type=None, cancel_after=None, post_only=None, hidden=None, iceberg=None, visible_size=None, **params)[source]
Create a spot limit order
https://docs.kucoin.com/#place-a-new-order
- Parameters:
symbol (string) – Name of symbol e.g. KCS-BTC
side (string) – buy or sell
price (string) – Name of coin
size (string) – Amount of base currency to buy or sell
client_oid (string) – (optional) Unique order_id default flat_uuid()
remark (string) – (optional) remark for the order, max 100 utf8 characters
stp (string) – (optional) self trade protection CN, CO, CB or DC (default is None)
trade_type (string) – (optional) - deprecated - TRADE (spot) is supported only (default is TRADE)
time_in_force (string) – (optional) GTC, GTT, IOC, or FOK (default is GTC)
stop – (deprecated) not supported
stop_price – (deprecated) not supported
cancel_after (string) – (optional) number of seconds to cancel the order if not filled required time_in_force to be GTT
post_only (bool) – (optional) indicates that the order should only make liquidity. If any part of the order results in taking liquidity, the order will be rejected and no part of it will execute.
hidden (bool) – (optional) Orders not displayed in order book
iceberg (bool) – (optional) Only visible portion of the order is displayed in the order book
visible_size (string) – (optional) The maximum visible size of an iceberg order
order = client.create_limit_order('KCS-BTC', Client.SIDE_BUY, '0.01', '1000')
- Returns:
ApiResponse
{ "orderOid": "596186ad07015679730ffa02" }
- Raises:
KucoinResponseException, KucoinAPIException, LimitOrderException
- create_market_order(symbol, side, size=None, funds=None, client_oid=None, remark=None, stp=None, **params)[source]
Create a spot market order
One of size or funds must be set
https://www.kucoin.com/docs/rest/spot-trading/orders/place-order
- Parameters:
symbol (string) – Name of symbol e.g. KCS-BTC
side (string) – buy or sell
size (string) – (optional) Desired amount in base currency
funds (string) – (optional) Desired amount of quote currency to use
client_oid (string) – (optional) Unique order id (default flat_uuid())
remark (string) – (optional) remark for the order, max 100 utf8 characters
stp (string) – (optional) self trade protection CN, CO, CB or DC (default is None)
order = client.create_market_order('ETH-USDT', Client.SIDE_BUY, size=20)
- Returns:
ApiResponse
{ "orderOid": "596186ad07015679730ffa02" }
- Raises:
KucoinResponseException, KucoinAPIException, MarketOrderException
- get_fills(trade_type, order_id=None, symbol=None, side=None, type=None, start=None, end=None, page=None, limit=None, **params)[source]
Get a list of recent fills.
https://www.kucoin.com/docs/rest/spot-trading/fills/get-filled-list
- Parameters:
trade_type (string) – TRADE (Spot Trading), MARGIN_TRADE (Margin Trading), MARGIN_ISOLATED_TRADE (Isolated Margin Trading), TRADE as default.
order_id (string) – (optional) OrderId
symbol (string) – (optional) Name of symbol e.g. KCS-BTC
side (string) – (optional) buy or sell
type (string) – (optional) limit, market, limit_stop or market_stop
start (int) – (optional) Start time as unix timestamp
end (int) – (optional) End time as unix timestamp
page (int) – (optional) Page number
limit (int) – (optional) Number of orders
fills = client.get_fills('TRADE')
- Returns:
ApiResponse
{ "currentPage": 1, "pageSize": 1, "totalNum": 251915, "totalPage": 251915, "items": [ { "symbol": "BTC-USDT", "tradeId": "5c35c02709e4f67d5266954e", "orderId": "5c35c02703aa673ceec2a168", "counterOrderId": "5c1ab46003aa676e487fa8e3", "side": "buy", "liquidity": "taker", "forceTaker": true, "price": "0.083", "size": "0.8424304", "funds": "0.0699217232", "fee": "0", "feeRate": "0", "feeCurrency": "USDT", "stop": "", "type": "limit", "createdAt": 1547026472000, "tradeType": "TRADE" } ] }
- Raises:
KucoinResponseException, KucoinAPIException
- get_order(order_id, **params)[source]
Get order details
https://www.kucoin.com/docs/rest/spot-trading/orders/get-order-details-by-orderid
- Parameters:
order_id (str) – orderOid value
order = client.get_order('5c35c02703aa673ceec2a168')
- Returns:
ApiResponse
{ "id": "5c35c02703aa673ceec2a168", "symbol": "BTC-USDT", "opType": "DEAL", "type": "limit", "side": "buy", "price": "10", "size": "2", "funds": "0", "dealFunds": "0.166", "dealSize": "2", "fee": "0", "feeCurrency": "USDT", "stp": "", "stop": "", "stopTriggered": false, "stopPrice": "0", "timeInForce": "GTC", "postOnly": false, "hidden": false, "iceberge": false, "visibleSize": "0", "cancelAfter": 0, "channel": "IOS", "clientOid": null, "remark": null, "tags": null, "isActive": false, "cancelExist": false, "createdAt": 1547026471000 }
- Raises:
KucoinResponseException, KucoinAPIException
- get_order_by_client_oid(client_oid, **params)[source]
Get order details by clientOid
https://www.kucoin.com/docs/rest/spot-trading/orders/get-order-details-by-clientoid
- Parameters:
client_oid (str) – clientOid value
order = client.get_order_by_client_oid('6d539dc614db312')
- Returns:
ApiResponse
{ "id": "5f3113a1c9b6d539dc614dc6", "symbol": "KCS-BTC", "opType": "DEAL", "type": "limit", "side": "buy", "price": "0.00001", "size": "1", "funds": "0", "dealFunds": "0", "dealSize": "0", "fee": "0", "feeCurrency": "BTC", "stp": "", "stop": "", "stopTriggered": false, "stopPrice": "0", "timeInForce": "GTC", "postOnly": false, "hidden": false, "iceberg": false, "visibleSize": "0", "cancelAfter": 0, "channel": "API", "clientOid": "6d539dc614db312", "remark": "", "tags": "", "isActive": true, "cancelExist": false, "createdAt": 1597051810000, "tradeType": "TRADE" }
- Raises:
KucoinResponseException, KucoinAPIException
- get_orders(symbol=None, status=None, side=None, order_type=None, start=None, end=None, page=None, limit=None, trade_type=None, **params)[source]
Get list of orders
https://www.kucoin.com/docs/rest/spot-trading/orders/get-order-list
- Parameters:
symbol (string) – (optional) Name of symbol e.g. KCS-BTC
status (string) – (optional) Specify status active or done (default done)
side (string) – (optional) buy or sell
order_type (string) – (optional) limit, market, limit_stop or market_stop
trade_type (string) – (optional) The type of trading : TRADE - spot trading, MARGIN_TRADE - cross margin trading, MARGIN_ISOLATED_TRADE - isolated margin trading default is TRADE
start (string) – (optional) Start time as unix timestamp
end (string) – (optional) End time as unix timestamp
page (int) – (optional) Page to fetch
limit (int) – (optional) Number of orders
orders = client.get_orders(symbol='KCS-BTC', status='active')
- Returns:
ApiResponse
{ "code": "200000", "data": { "currentPage": 1, "pageSize": 50, "totalNum": 1, "totalPage": 1, "items": [ { "id": "67320d92429d8b0007a962d0", "symbol": "ETH-USDT", "opType": "DEAL", "type": "limit", "side": "buy", "price": "100", "size": "0.01", "funds": "0", "dealFunds": "0", "dealSize": "0", "fee": "0", "feeCurrency": "USDT", "stp": null, "stop": null, "stopTriggered": false, "stopPrice": "0", "timeInForce": "GTC", "postOnly": false, "hidden": false, "iceberg": false, "visibleSize": "0", "cancelAfter": 0, "channel": "API", "clientOid": null, "remark": null, "tags": "partner:ccxt", "isActive": true, "cancelExist": false, "createdAt": 1731333522333, "tradeType": "TRADE" } ] } }
- Raises:
KucoinResponseException, KucoinAPIException