Trading Endpoints¶
-
class
kucoin.client.
Client
(api_key, api_secret, passphrase, sandbox=False, requests_params=None)[source] -
cancel_all_orders
(symbol=None)[source] Cancel all orders
https://docs.kucoin.com/#cancel-all-orders
res = client.cancel_all_orders()
Returns: ApiResponse { "cancelledOrderIds": [ "5bd6e9286d99522a52e458de" ] }
Raises: KucoinResponseException, KucoinAPIException
-
cancel_order
(order_id)[source] Cancel an order
https://docs.kucoin.com/#cancel-an-order
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
-
create_limit_order
(symbol, side, price, size, client_oid=None, remark=None, time_in_force=None, stop=None, stop_price=None, stp=None, cancel_after=None, post_only=None, hidden=None, iceberg=None, visible_size=None)[source] Create an 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)
- time_in_force (string) – (optional) GTC, GTT, IOC, or FOK (default is GTC)
- stop (string) – (optional) stop type loss or entry - requires stop_price
- stop_price (string) – (optional) trigger price for stop order
- 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 (bool) – (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)[source] Create a market order
One of size or funds must be set
https://docs.kucoin.com/#place-a-new-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('NEO', Client.SIDE_BUY, size=20)
Returns: ApiResponse { "orderOid": "596186ad07015679730ffa02" }
Raises: KucoinResponseException, KucoinAPIException, MarketOrderException
-
get_fills
(order_id=None, symbol=None, side=None, order_type=None, start=None, end=None, page=None, limit=None)[source] Get a list of recent fills.
https://docs.kucoin.com/#list-fills
Parameters: - order_id (string) – (optional) generated order id
- symbol (string) – (optional) Name of symbol e.g. KCS-BTC
- side (string) – (optional) buy or sell
- order_type (string) – (optional) limit, market, limit_stop or market_stop
- start (string) – Start time as unix timestamp (optional)
- end (string) – End time as unix timestamp (optional)
- page (int) – optional - Page to fetch
- limit (int) – optional - Number of orders
fills = client.get_fills()
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 } ] }
Raises: KucoinResponseException, KucoinAPIException
-
get_order
(order_id)[source] Get order details
https://docs.kucoin.com/#get-an-order
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_orders
(symbol=None, status=None, side=None, order_type=None, start=None, end=None, page=None, limit=None)[source] Get list of orders
https://docs.kucoin.com/#list-orders
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
- 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 { "currentPage": 1, "pageSize": 1, "totalNum": 153408, "totalPage": 153408, "items": [ { "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
-