KucoinTrading: Spot Order Management
KucoinTrading: Spot Order Management
Details
Provides methods for placing, cancelling, and querying spot orders on KuCoin. All order operations use the HF (High-Frequency) trading endpoints. Inherits from KucoinBase.
Purpose and Scope
Order Placement: Place single or batch limit/market orders with full parameter control.
Order Testing: Validate order parameters without execution via the test endpoint.
Order Cancellation: Cancel by order ID, client OID, partially, by symbol, or all at once.
Order Queries: Retrieve order details, open orders, closed orders, fills, and symbols with activity.
Usage
All methods require authentication (valid API key, secret, passphrase).
The KucoinTrading class consolidates functionality previously split across
KucoinSpotAddOrder, KucoinSpotCancelOrder, and KucoinSpotGetOrder.
Endpoints Covered
| Method | Endpoint | HTTP |
| add_order | POST /api/v1/hf/orders | POST |
| add_order_test | POST /api/v1/hf/orders/test | POST |
| add_order_batch | POST /api/v1/hf/orders/multi | POST |
| cancel_order_by_id | DELETE /api/v1/hf/orders/{orderId} | DELETE |
| cancel_order_by_client_oid | DELETE /api/v1/hf/orders/client-order/{clientOid} | DELETE |
| cancel_partial_order | DELETE /api/v1/hf/orders/cancel/{orderId} | DELETE |
| cancel_all_by_symbol | DELETE /api/v1/hf/orders | DELETE |
| cancel_all | DELETE /api/v1/hf/orders/cancelAll | DELETE |
| get_order_by_id | GET /api/v1/hf/orders/{orderId} | GET |
| get_order_by_client_oid | GET /api/v1/hf/orders/client-order/{clientOid} | GET |
| get_fills | GET /api/v1/hf/fills | GET |
| get_symbols_with_open_orders | GET /api/v1/hf/orders/active/symbols | GET |
| get_open_orders | GET /api/v1/hf/orders/active | GET |
| get_closed_orders | GET /api/v1/hf/orders/done | GET |
| add_order_sync | POST /api/v1/hf/orders/sync | POST |
| add_order_batch_sync | POST /api/v1/hf/orders/multi/sync | POST |
| cancel_order_by_id_sync | DELETE /api/v1/hf/orders/sync/{orderId} | DELETE |
| cancel_order_by_client_oid_sync | DELETE /api/v1/hf/orders/sync/client-order/{clientOid} | DELETE |
| modify_order | POST /api/v1/hf/orders/alter | POST |
| set_dcp | POST /api/v1/hf/orders/dead-cancel-all | POST |
| get_dcp | GET /api/v1/hf/orders/dead-cancel-all/query | GET |
Order Types and Parameters
Limit Orders require price and size. Optional: timeInForce, cancelAfter,
postOnly, hidden, iceberg, visibleSize.
Market Orders require either size (base currency qty) or funds (quote currency qty),
but not both. price must NOT be specified.
Self-Trade Prevention (STP)
Use the stp parameter to control behaviour when your orders would match each other:
"CN"(Cancel Newest): Cancel the incoming order."CO"(Cancel Oldest): Cancel the resting order."CB"(Cancel Both): Cancel both orders."DC"(Decrement and Cancel): Reduce quantities.
Time-In-Force Options
"GTC"(Good Till Cancelled): Remains until filled or cancelled. Default."GTT"(Good Till Time): Cancels aftercancelAfterseconds."IOC"(Immediate Or Cancel): Fill immediately or cancel remainder."FOK"(Fill Or Kill): Fill entirely or cancel completely.
Super class
kucoin::KucoinBase -> KucoinTrading
Methods
Inherited methods
Method add_order()
Place an Order
Places a new limit or market order on KuCoin Spot via the HF endpoint.
Parameters are validated by validate_order_params() before submission.
Workflow
Validation: Calls
validate_order_params()for type-specific checks.Request: Authenticated POST with order body.
Parsing: Returns
data.tablewithorder_idandclient_oid.
Automated Trading Usage
Limit Orders: Set
priceandsizefor precise entry/exit points.Market Orders: Use
sizefor base-amount orfundsfor quote-amount execution.Post-Only: Set
postOnly = TRUEto guarantee maker fees (order rejected if it would match).Iceberg Orders: Set
iceberg = TRUEwithvisibleSizeto hide large order quantities.
curl
curl --location --request POST 'https://api.kucoin.com/api/v1/hf/orders' \
--header 'Content-Type: application/json' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2' \
--data-raw '{"type":"limit","symbol":"BTC-USDT","side":"buy","price":"50000","size":"0.00001"}'Usage
KucoinTrading$add_order(
type,
symbol,
side,
clientOid = NULL,
price = NULL,
size = NULL,
funds = NULL,
stp = NULL,
tags = NULL,
remark = NULL,
timeInForce = NULL,
cancelAfter = NULL,
postOnly = NULL,
hidden = NULL,
iceberg = NULL,
visibleSize = NULL
)Arguments
typeCharacter;
"limit"or"market".symbolCharacter; trading pair (e.g.,
"BTC-USDT").sideCharacter;
"buy"or"sell".clientOidCharacter or NULL; unique client order ID (max 40 chars).
priceNumeric or NULL; price for limit orders. Must align with
priceIncrement. Required for limit orders; must NOT be set for market orders.sizeNumeric or NULL; quantity in base currency. Must align with
baseIncrement. Required for limit orders; optional for market orders (mutually exclusive withfunds).fundsNumeric or NULL; amount in quote currency for market orders. Mutually exclusive with
size. Not applicable for limit orders.stpCharacter or NULL; self-trade prevention:
"CN","CO","CB","DC".tagsCharacter or NULL; order tag (max 20 ASCII chars).
remarkCharacter or NULL; remarks (max 20 ASCII chars).
timeInForceCharacter or NULL;
"GTC","GTT","IOC","FOK".cancelAfterNumeric or NULL; auto-cancel seconds (requires
timeInForce = "GTT").postOnlyLogical or NULL; if TRUE, order rejected if it would match immediately.
hiddenLogical or NULL; if TRUE, order hidden from order book.
icebergLogical or NULL; if TRUE, only
visibleSizeis shown.visibleSizeNumeric or NULL; visible quantity for iceberg orders.
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with columns:
order_id(character): KuCoin-assigned order identifier.client_oid(character): Client-provided order identifier.
Examples
\dontrun{
trading <- KucoinTrading$new()
# Limit buy order
order <- trading$add_order(
type = "limit", symbol = "BTC-USDT", side = "buy",
price = 50000, size = 0.00001
)
print(order$order_id)
# Market sell order by size
order <- trading$add_order(
type = "market", symbol = "BTC-USDT", side = "sell",
size = 0.00001
)
}
Method add_order_test()
Test Order Placement
Simulates placing an order without execution. Validates all parameters
and authentication exactly as add_order(), but no order is actually created.
Automated Trading Usage
Parameter Validation: Verify order parameters are correct before live submission.
Auth Testing: Confirm API credentials work for order placement.
Integration Testing: Test your trading pipeline end-to-end without risk.
curl
curl --location --request POST 'https://api.kucoin.com/api/v1/hf/orders/test' \
--header 'Content-Type: application/json' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2' \
--data-raw '{"type":"limit","symbol":"BTC-USDT","side":"buy","price":"50000","size":"0.00001"}'Usage
KucoinTrading$add_order_test(
type,
symbol,
side,
clientOid = NULL,
price = NULL,
size = NULL,
funds = NULL,
stp = NULL,
tags = NULL,
remark = NULL,
timeInForce = NULL,
cancelAfter = NULL,
postOnly = NULL,
hidden = NULL,
iceberg = NULL,
visibleSize = NULL
)Arguments
typeCharacter;
"limit"or"market".symbolCharacter; trading pair (e.g.,
"BTC-USDT").sideCharacter;
"buy"or"sell".clientOidCharacter or NULL; unique client order ID (max 40 chars).
priceNumeric or NULL; price for limit orders.
sizeNumeric or NULL; quantity in base currency.
fundsNumeric or NULL; amount in quote currency for market orders.
stpCharacter or NULL; self-trade prevention:
"CN","CO","CB","DC".tagsCharacter or NULL; order tag (max 20 ASCII chars).
remarkCharacter or NULL; remarks (max 20 ASCII chars).
timeInForceCharacter or NULL;
"GTC","GTT","IOC","FOK".cancelAfterNumeric or NULL; auto-cancel seconds (requires
timeInForce = "GTT").postOnlyLogical or NULL; if TRUE, order rejected if it would match immediately.
hiddenLogical or NULL; if TRUE, order hidden from order book.
icebergLogical or NULL; if TRUE, only
visibleSizeis shown.visibleSizeNumeric or NULL; visible quantity for iceberg orders.
Method add_order_batch()
Place Batch Orders
Places up to 20 orders in a single request. Each order is validated
independently. Failed orders return success = FALSE with a fail_msg.
Workflow
Validation: Each order in the list is validated via
validate_batch_order().Request: Authenticated POST with
orderListbody.Parsing: Returns per-order results with success/failure status.
Automated Trading Usage
Portfolio Rebalancing: Submit multiple orders across pairs simultaneously.
Grid Trading: Place a grid of limit orders at different price levels.
Error Handling: Check
successcolumn to identify and retry failed orders.
curl
curl --location --request POST 'https://api.kucoin.com/api/v1/hf/orders/multi' \
--header 'Content-Type: application/json' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2' \
--data-raw '{"orderList":[{"clientOid":"id1","symbol":"BTC-USDT","type":"limit","side":"buy","price":"30000","size":"0.00001"}]}'Arguments
order_listList of named lists; each containing order parameters (
type,symbol,side, plus optional fields). Maximum 20 orders.
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with per-order results:
order_id(character): KuCoin order ID (if successful).client_oid(character): Client order ID (if provided).success(logical): Whether the order was placed successfully.fail_msg(character): Error message (if failed).
Examples
\dontrun{
trading <- KucoinTrading$new()
orders <- trading$add_order_batch(list(
list(type = "limit", symbol = "BTC-USDT", side = "buy",
price = "30000", size = "0.00001", clientOid = "order1"),
list(type = "limit", symbol = "ETH-USDT", side = "buy",
price = "2000", size = "0.001", clientOid = "order2")
))
print(orders[success == TRUE, .(order_id, client_oid)])
print(orders[success == FALSE, .(fail_msg)])
}
Method cancel_order_by_id()
Cancel Order by Order ID
Cancels a specific spot HF order by its KuCoin-assigned order ID.
curl
curl --location --request DELETE \
'https://api.kucoin.com/api/v1/hf/orders/671124f9365ccb00073debd4?symbol=BTC-USDT' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Arguments
orderIdCharacter; the KuCoin order ID to cancel.
symbolCharacter; trading pair (e.g.,
"BTC-USDT").
Method cancel_order_by_client_oid()
Cancel Order by Client OID
Cancels a spot HF order by its client-assigned order ID.
API Endpoint
DELETE https://api.kucoin.com/api/v1/hf/orders/client-order/{clientOid}?symbol={symbol}
curl
curl --location --request DELETE \
'https://api.kucoin.com/api/v1/hf/orders/client-order/myClientOid123?symbol=BTC-USDT' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Method cancel_partial_order()
Cancel Partial Order
Decreases the quantity of an existing open order without fully cancelling it.
API Endpoint
DELETE https://api.kucoin.com/api/v1/hf/orders/cancel/{orderId}?symbol={symbol}&cancelSize={cancelSize}
Automated Trading Usage
Position Scaling: Reduce open order size without losing queue priority.
Risk Management: Partially withdraw from a large resting order.
curl
curl --location --request DELETE \
'https://api.kucoin.com/api/v1/hf/orders/cancel/671124f9365ccb00073debd4?symbol=BTC-USDT&cancelSize=0.00001' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Arguments
orderIdCharacter; order ID.
symbolCharacter; trading pair (e.g.,
"BTC-USDT").cancelSizeNumeric; quantity to cancel from the order.
Method cancel_all_by_symbol()
Cancel All Orders by Symbol
Cancels all open HF orders for a specific trading pair.
Automated Trading Usage
Emergency Stop: Cancel all orders for a pair when risk limits are breached.
Strategy Reset: Clear all open orders before deploying a new strategy.
Method cancel_all()
Cancel All Orders
Cancels all open spot HF orders across all trading pairs.
Automated Trading Usage
Emergency Kill Switch: Cancel everything when a critical error is detected.
End of Session: Clear all orders at the end of a trading session.
Method get_order_by_id()
Get Order by Order ID
Retrieves full details for a specific order by its KuCoin-assigned ID.
curl
curl --location --request GET \
'https://api.kucoin.com/api/v1/hf/orders/671124f9365ccb00073debd4?symbol=BTC-USDT' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Arguments
orderIdCharacter; the KuCoin order ID.
symbolCharacter; trading pair (e.g.,
"BTC-USDT").
Method get_order_by_client_oid()
Get Order by Client OID
Retrieves full details for a specific order by its client-assigned ID.
curl
curl --location --request GET \
'https://api.kucoin.com/api/v1/hf/orders/client-order/myClientOid123?symbol=BTC-USDT' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Method get_fills()
Get Trade Fills
Retrieves execution history for filled or partially filled HF orders. Returns detailed fill information including fees, liquidity type, and trade IDs.
Workflow
Request: Authenticated GET with symbol (required) and optional filters.
Parsing: Extracts
itemsarray, converts todata.table.Timestamp Conversion: Converts
created_at(ms) todatetime_created.
Automated Trading Usage
P&L Tracking: Use
price,size,fee, andfee_currencyfor profit calculations.Fill Analysis: Check
liquidity(maker/taker) to optimise execution strategy.Audit Trail: Build comprehensive trade logs with
trade_idfor reconciliation.
curl
curl --location --request GET \
'https://api.kucoin.com/api/v1/hf/fills?symbol=BTC-USDT&limit=100' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'JSON Response
{
"code": "200000",
"data": {
"items": [
{
"id": 19814995255305,
"orderId": "6717422bd51c29000775ea03",
"counterOrderId": "67174228135f9e000709da8c",
"tradeId": 11029373945659392,
"symbol": "BTC-USDT",
"side": "buy",
"liquidity": "taker",
"type": "limit",
"forceTaker": false,
"price": "67717.6",
"size": "0.00001",
"funds": "0.677176",
"fee": "0.000677176",
"feeRate": "0.001",
"feeCurrency": "USDT",
"stop": "",
"tradeType": "TRADE",
"taxRate": "0",
"tax": "0",
"createdAt": 1729577515473
}
],
"lastId": 19814995255305
}
}Usage
KucoinTrading$get_fills(
symbol,
orderId = NULL,
side = NULL,
type = NULL,
lastId = NULL,
limit = NULL,
startAt = NULL,
endAt = NULL
)Arguments
symbolCharacter; trading pair (e.g.,
"BTC-USDT"). Required.orderIdCharacter or NULL; filter by specific order ID.
sideCharacter or NULL;
"buy"or"sell".typeCharacter or NULL;
"limit"or"market".lastIdCharacter or NULL; pagination cursor for fetching next page.
limitInteger or NULL; results per page (default 100, max 200).
startAtInteger or NULL; start timestamp in milliseconds.
endAtInteger or NULL; end timestamp in milliseconds.
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with columns:
id(numeric): Fill identifier.order_id(character): Parent order ID.counter_order_id(character): Counterparty order ID.trade_id(numeric): Trade identifier.symbol(character): Trading pair.side(character): Trade direction.liquidity(character):"maker"or"taker".type(character): Order type.price(character): Fill price.size(character): Fill size.funds(character): Fill value in quote currency.fee(character): Fee charged.fee_rate(character): Fee rate applied.fee_currency(character): Currency of fee.datetime_created(POSIXct): Creation datetime.
Method get_symbols_with_open_orders()
Get Symbols with Open Orders
Returns a list of symbols that have at least one active HF order. Useful for determining which pairs need attention.
Automated Trading Usage
Order Monitoring: Quickly check which symbols have active orders.
Cleanup: Iterate over symbols to cancel or manage outstanding orders.
Method get_open_orders()
Get Open Orders
Retrieves all currently open HF orders for a specific symbol.
Automated Trading Usage
Order Book Reconciliation: Compare your open orders against expected state.
Stale Order Detection: Identify and cancel orders that have been open too long.
Position Management: Track total open exposure per symbol.
curl
curl --location --request GET \
'https://api.kucoin.com/api/v1/hf/orders/active?symbol=BTC-USDT' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Method get_closed_orders()
Get Closed Orders
Retrieves recently closed (filled or cancelled) HF orders for a symbol. Supports filtering by side, type, and time range.
Automated Trading Usage
Order History: Build trade logs from completed orders.
Fill Rate Analysis: Calculate fill rates across order types and time periods.
Strategy Evaluation: Review historical order outcomes for strategy tuning.
curl
curl --location --request GET \
'https://api.kucoin.com/api/v1/hf/orders/done?symbol=BTC-USDT&limit=50' \
--header 'KC-API-KEY: your-api-key' \
--header 'KC-API-SIGN: your-signature' \
--header 'KC-API-TIMESTAMP: 1729176273859' \
--header 'KC-API-PASSPHRASE: your-passphrase' \
--header 'KC-API-KEY-VERSION: 2'Usage
KucoinTrading$get_closed_orders(
symbol,
side = NULL,
type = NULL,
startAt = NULL,
endAt = NULL,
limit = NULL,
lastId = NULL
)Arguments
symbolCharacter; trading pair (e.g.,
"BTC-USDT").sideCharacter or NULL;
"buy"or"sell".typeCharacter or NULL;
"limit"or"market".startAtInteger or NULL; start timestamp in milliseconds.
endAtInteger or NULL; end timestamp in milliseconds.
limitInteger or NULL; results per page (max 200).
lastIdCharacter or NULL; pagination cursor.
Method add_order_sync()
Place an Order (Synchronous Return)
Places a new limit or market order and waits for the matching engine to
process it before returning. Returns the fill result in one round trip,
eliminating the need to poll get_order_by_id().
Automated Trading Usage
Low-Latency Fills: Get fill result in a single round trip instead of polling.
Market Orders: Ideal for market orders where immediate fill confirmation is critical.
Race-Free: No gap between order placement and status check.
Usage
KucoinTrading$add_order_sync(
type,
symbol,
side,
clientOid = NULL,
price = NULL,
size = NULL,
funds = NULL,
stp = NULL,
tags = NULL,
remark = NULL,
timeInForce = NULL,
cancelAfter = NULL,
postOnly = NULL,
hidden = NULL,
iceberg = NULL,
visibleSize = NULL
)Arguments
typeCharacter;
"limit"or"market".symbolCharacter; trading pair (e.g.,
"BTC-USDT").sideCharacter;
"buy"or"sell".clientOidCharacter or NULL; unique client order ID (max 40 chars).
priceNumeric or NULL; price for limit orders.
sizeNumeric or NULL; quantity in base currency.
fundsNumeric or NULL; amount in quote currency for market orders.
stpCharacter or NULL; self-trade prevention:
"CN","CO","CB","DC".tagsCharacter or NULL; order tag (max 20 ASCII chars).
remarkCharacter or NULL; remarks (max 20 ASCII chars).
timeInForceCharacter or NULL;
"GTC","GTT","IOC","FOK".cancelAfterNumeric or NULL; auto-cancel seconds (requires
timeInForce = "GTT").postOnlyLogical or NULL; if TRUE, order rejected if it would match immediately.
hiddenLogical or NULL; if TRUE, order hidden from order book.
icebergLogical or NULL; if TRUE, only
visibleSizeis shown.visibleSizeNumeric or NULL; visible quantity for iceberg orders.
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with columns:
order_id(character): KuCoin-assigned order identifier.order_time(numeric): Order placement time in milliseconds.origin_size(character): Original order size.deal_size(character): Filled size.remain_size(character): Remaining unfilled size.canceled_size(character): Cancelled size.status(character):"open"or"done".
Method add_order_batch_sync()
Place Batch Orders (Synchronous Return)
Places up to 20 orders in a single request and waits for the matching engine to process them before returning. Returns per-order fill results.
Automated Trading Usage
Grid Trading: Place a grid of limit orders and get immediate fill status for all.
Rebalancing: Submit multiple orders with guaranteed fill confirmation.
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with per-order results
including order_id, success, status, deal_size, remain_size, canceled_size.
Examples
\dontrun{
trading <- KucoinTrading$new()
orders <- trading$add_order_batch_sync(list(
list(type = "limit", symbol = "BTC-USDT", side = "buy",
price = "30000", size = "0.00001", clientOid = "order1"),
list(type = "limit", symbol = "ETH-USDT", side = "buy",
price = "2000", size = "0.001", clientOid = "order2")
))
print(orders[success == TRUE, .(order_id, status, deal_size)])
}
Method cancel_order_by_id_sync()
Cancel Order by Order ID (Synchronous Return)
Cancels an order and waits for the cancellation to complete before returning. Returns the final order state including fill and cancellation sizes.
Automated Trading Usage
Atomic Cancel: Confirm cancellation and get final fill state in one call.
Partial Fill Detection: Check
deal_sizeto know if any fills occurred before cancellation.
Arguments
orderIdCharacter; the KuCoin order ID to cancel.
symbolCharacter; trading pair (e.g.,
"BTC-USDT").
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with columns:
order_id(character): Order ID.origin_size(character): Original order size.deal_size(character): Filled size.remain_size(character): Remaining size.canceled_size(character): Cancelled size.status(character):"open"or"done".
Method cancel_order_by_client_oid_sync()
Cancel Order by Client OID (Synchronous Return)
Cancels an order by client OID and waits for completion before returning.
API Endpoint
DELETE https://api.kucoin.com/api/v1/hf/orders/sync/client-order/{clientOid}?symbol={symbol}
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with columns:
client_oid(character): Client order ID.origin_size(character): Original order size.deal_size(character): Filled size.remain_size(character): Remaining size.canceled_size(character): Cancelled size.status(character):"open"or"done".
Method modify_order()
Modify Order
Amends the price and/or size of an existing open order atomically. Internally, KuCoin cancels the original order and places a replacement. If the new size is less than the already filled quantity, the order is simply cancelled with no replacement.
Automated Trading Usage
Price Adjustment: Move a resting limit order to a new price level without cancel+replace gap.
Size Adjustment: Increase or decrease order size atomically.
Trailing Logic: Continuously adjust price as the market moves.
Usage
KucoinTrading$modify_order(
symbol,
orderId = NULL,
clientOid = NULL,
newPrice = NULL,
newSize = NULL
)Arguments
symbolCharacter; trading pair (e.g.,
"BTC-USDT"). Required.orderIdCharacter or NULL; KuCoin order ID. At least one of
orderIdorclientOidrequired.clientOidCharacter or NULL; client order ID. At least one of
orderIdorclientOidrequired.newPriceCharacter or NULL; new order price. At least one of
newPriceornewSizerequired.newSizeCharacter or NULL; new order size. At least one of
newPriceornewSizerequired.
Method set_dcp()
Set DCP (Dead Connection Protection)
Configures KuCoin's dead-man's switch. If no user requests are received within the timeout window, KuCoin automatically cancels all open HF orders for the specified symbols (or all symbols if none specified).
Automated Trading Usage
Crash Safety: Heartbeat every N seconds; if bot crashes, KuCoin cancels all orders.
Network Failsafe: Protects against network outages leaving stale orders.
Selective Protection: Specify symbols to protect only active trading pairs.
Arguments
timeoutInteger; trigger duration in seconds. Use
-1to disable, or5to86400.symbolsCharacter or NULL; comma-separated trading pairs (max 50). Empty or NULL applies to all pairs.
Method get_dcp()
Get DCP Settings
Queries the current Dead Connection Protection (dead-man's switch)
configuration. Returns an empty data.table if DCP is not configured.
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with columns:
timeout(integer): Auto-cancel trigger time in seconds.-1if unset.symbols(character): Comma-separated trading pairs, or empty for all.current_time(integer): Current server time in seconds.trigger_time(integer): When cancellation will trigger.
Examples
if (FALSE) { # \dontrun{
# Synchronous
trading <- KucoinTrading$new()
order <- trading$add_order_test(type = "limit", symbol = "BTC-USDT",
side = "buy", price = 50000, size = 0.0001)
print(order)
# Asynchronous
trading_async <- KucoinTrading$new(async = TRUE)
main <- coro::async(function() {
order <- await(trading_async$add_order_test(
type = "limit", symbol = "BTC-USDT", side = "buy",
price = 50000, size = 0.0001
))
print(order)
})
main()
while (!later::loop_empty()) later::run_now()
} # }
## ------------------------------------------------
## Method `KucoinTrading$add_order`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
# Limit buy order
order <- trading$add_order(
type = "limit", symbol = "BTC-USDT", side = "buy",
price = 50000, size = 0.00001
)
print(order$order_id)
# Market sell order by size
order <- trading$add_order(
type = "market", symbol = "BTC-USDT", side = "sell",
size = 0.00001
)
} # }
## ------------------------------------------------
## Method `KucoinTrading$add_order_test`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
test <- trading$add_order_test(
type = "limit", symbol = "BTC-USDT", side = "buy",
price = 50000, size = 0.00001
)
print(test)
} # }
## ------------------------------------------------
## Method `KucoinTrading$add_order_batch`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
orders <- trading$add_order_batch(list(
list(type = "limit", symbol = "BTC-USDT", side = "buy",
price = "30000", size = "0.00001", clientOid = "order1"),
list(type = "limit", symbol = "ETH-USDT", side = "buy",
price = "2000", size = "0.001", clientOid = "order2")
))
print(orders[success == TRUE, .(order_id, client_oid)])
print(orders[success == FALSE, .(fail_msg)])
} # }
## ------------------------------------------------
## Method `KucoinTrading$cancel_order_by_id`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
result <- trading$cancel_order_by_id("671124f9365ccb00073debd4", "BTC-USDT")
print(result$order_id)
} # }
## ------------------------------------------------
## Method `KucoinTrading$cancel_order_by_client_oid`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
result <- trading$cancel_order_by_client_oid("myClientOid123", "BTC-USDT")
print(result$client_oid)
} # }
## ------------------------------------------------
## Method `KucoinTrading$cancel_partial_order`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
result <- trading$cancel_partial_order(
"671124f9365ccb00073debd4", "BTC-USDT", cancelSize = 0.00001
)
} # }
## ------------------------------------------------
## Method `KucoinTrading$cancel_all_by_symbol`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
trading$cancel_all_by_symbol("BTC-USDT")
} # }
## ------------------------------------------------
## Method `KucoinTrading$cancel_all`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
trading$cancel_all()
} # }
## ------------------------------------------------
## Method `KucoinTrading$get_order_by_id`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
order <- trading$get_order_by_id("671124f9365ccb00073debd4", "BTC-USDT")
print(order)
} # }
## ------------------------------------------------
## Method `KucoinTrading$get_order_by_client_oid`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
order <- trading$get_order_by_client_oid("myClientOid123", "BTC-USDT")
print(order)
} # }
## ------------------------------------------------
## Method `KucoinTrading$get_fills`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
fills <- trading$get_fills("BTC-USDT")
# Calculate total fees
total_fees <- fills[, sum(as.numeric(fee))]
print(paste("Total fees:", total_fees, "USDT"))
} # }
## ------------------------------------------------
## Method `KucoinTrading$get_symbols_with_open_orders`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
active <- trading$get_symbols_with_open_orders()
print(active$symbols)
} # }
## ------------------------------------------------
## Method `KucoinTrading$get_open_orders`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
open_orders <- trading$get_open_orders("BTC-USDT")
print(open_orders[, .(order_id, side, price, size, datetime_created)])
} # }
## ------------------------------------------------
## Method `KucoinTrading$get_closed_orders`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
closed <- trading$get_closed_orders("BTC-USDT", limit = 20)
print(closed[, .(order_id, side, price, size, datetime_created)])
} # }
## ------------------------------------------------
## Method `KucoinTrading$add_order_sync`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
order <- trading$add_order_sync(
type = "limit", symbol = "BTC-USDT", side = "buy",
price = 50000, size = 0.00001
)
cat("Status:", order$status, "Filled:", order$deal_size, "\n")
} # }
## ------------------------------------------------
## Method `KucoinTrading$add_order_batch_sync`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
orders <- trading$add_order_batch_sync(list(
list(type = "limit", symbol = "BTC-USDT", side = "buy",
price = "30000", size = "0.00001", clientOid = "order1"),
list(type = "limit", symbol = "ETH-USDT", side = "buy",
price = "2000", size = "0.001", clientOid = "order2")
))
print(orders[success == TRUE, .(order_id, status, deal_size)])
} # }
## ------------------------------------------------
## Method `KucoinTrading$cancel_order_by_id_sync`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
result <- trading$cancel_order_by_id_sync("671128ee365ccb0007534d45", "BTC-USDT")
cat("Status:", result$status, "Cancelled:", result$canceled_size, "\n")
} # }
## ------------------------------------------------
## Method `KucoinTrading$cancel_order_by_client_oid_sync`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
result <- trading$cancel_order_by_client_oid_sync("myClientOid123", "BTC-USDT")
cat("Status:", result$status, "\n")
} # }
## ------------------------------------------------
## Method `KucoinTrading$modify_order`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
result <- trading$modify_order(
symbol = "BTC-USDT",
orderId = "671124f9365ccb00073debd4",
newPrice = "51000"
)
cat("New order ID:", result$new_order_id, "\n")
} # }
## ------------------------------------------------
## Method `KucoinTrading$set_dcp`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
# Enable DCP with 30-second timeout for BTC-USDT
result <- trading$set_dcp(timeout = 30, symbols = "BTC-USDT")
cat("Trigger at:", result$trigger_time, "\n")
# Disable DCP
trading$set_dcp(timeout = -1)
} # }
## ------------------------------------------------
## Method `KucoinTrading$get_dcp`
## ------------------------------------------------
if (FALSE) { # \dontrun{
trading <- KucoinTrading$new()
dcp <- trading$get_dcp()
if (nrow(dcp) > 0) {
cat("DCP timeout:", dcp$timeout, "seconds\n")
cat("Symbols:", dcp$symbols, "\n")
}
} # }