KucoinStopOrders: Stop Order Management
KucoinStopOrders: Stop Order Management
Details
Provides methods for managing stop orders on KuCoin Spot. Inherits from KucoinBase.
Purpose and Scope
Stop Order Placement: Place limit or market stop orders with configurable trigger prices, self-trade prevention, time-in-force policies, and iceberg/hidden order support.
Order Cancellation: Cancel individual stop orders by KuCoin order ID, by client-assigned OID, or batch-cancel all stop orders matching filter criteria.
Order Queries: Retrieve details for individual stop orders by order ID or client OID, and list all stop orders with pagination and filtering support.
Usage
All methods require authentication (valid API key, secret, passphrase).
Stop orders remain dormant until the market price crosses the stop_price threshold.
Once triggered, a stop order becomes a regular limit or market order and is submitted
to the matching engine. Use stop orders for stop-loss, take-profit, and breakout strategies.
# Synchronous usage
stop <- KucoinStopOrders$new()
orders <- stop$get_order_list(query = list(symbol = "BTC-USDT"))
print(orders)
# Asynchronous usage
stop_async <- KucoinStopOrders$new(async = TRUE)
main <- coro::async(function() {
orders <- await(stop_async$get_order_list(query = list(symbol = "BTC-USDT")))
print(orders)
})
main()
while (!later::loop_empty()) later::run_now()Endpoints Covered
| Method | Endpoint | HTTP |
| add_order | POST /api/v1/stop-order | POST |
| cancel_order_by_id | DELETE /api/v1/stop-order/{orderId} | DELETE |
| cancel_order_by_client_oid | DELETE /api/v1/stop-order/cancelOrderByClientOid | DELETE |
| cancel_all | DELETE /api/v1/stop-order/cancel | DELETE |
| get_order_by_id | GET /api/v1/stop-order/{orderId} | GET |
| get_order_by_client_oid | GET /api/v1/stop-order/queryOrderByClientOid | GET |
| get_order_list | GET /api/v1/stop-order | GET |
Stop Order Types
Limit Stop Orders require price, size, and stopPrice. When the market
reaches the stopPrice, a limit order is placed at the specified price.
Optional parameters include timeInForce, cancelAfter, postOnly, hidden,
iceberg, and visibleSize.
Market Stop Orders require stopPrice and either size (base currency quantity)
or funds (quote currency amount), but not both. price must NOT be specified.
When the market reaches the stopPrice, a market order executes immediately at
the best available price.
How stopPrice Triggers Work:
For a buy stop order, the stop triggers when the last traded price rises to or above
stopPrice.For a sell stop order, the stop triggers when the last traded price falls to or below
stopPrice.Once triggered, the stop order is converted to a regular order (limit or market) and submitted to the matching engine. Trigger checks are based on the last trade price for the symbol.
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 -> KucoinStopOrders
Methods
Inherited methods
Method add_order()
Place a Stop Order
Places a stop order (limit or market) that triggers when the stop
price is reached. For limit stop orders, both price and size are
required. For market stop orders, either size or funds must be
specified (but not both), and price must not be set.
Workflow
Validation: Checks
type,side, andsymbolformat; enforces type-specific parameter constraints (e.g.,pricerequired for limit,funds/sizemutual exclusivity for market).Body Construction: Assembles the request body with required and optional parameters, converting numerics to character strings as needed.
Request: Authenticated POST to the stop order endpoint.
Parsing: Returns a
data.tablewith the assignedorder_idandclient_oid.
Automated Trading Usage
Stop-Loss: Place a sell stop order below your entry price to automatically exit a losing position.
Breakout Entry: Place a buy stop order above resistance to enter on a confirmed breakout.
Risk Management: Combine with
timeInForce = "GTT"andcancelAfterto auto-expire stale stop orders.
curl
curl --location --request POST 'https://api.kucoin.com/api/v1/stop-order' \
--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":"sell","stopPrice":"90000","price":"89500","size":"0.00001","tradeType":"TRADE"}'Usage
KucoinStopOrders$add_order(
type,
symbol,
side,
stopPrice,
clientOid = NULL,
price = NULL,
size = NULL,
funds = NULL,
stp = NULL,
remark = NULL,
timeInForce = NULL,
cancelAfter = NULL,
postOnly = NULL,
hidden = NULL,
iceberg = NULL,
visibleSize = NULL,
tradeType = "TRADE"
)Arguments
typeCharacter; order type, one of
"limit"or"market". Determines which additional parameters are required.symbolCharacter; trading pair symbol (e.g.,
"BTC-USDT"). Must match theBASE-QUOTEformat validated byverify_symbol().sideCharacter; order side, one of
"buy"or"sell".stopPriceCharacter; the trigger price at which the stop order activates. When the last traded price reaches this value, the order is placed.
clientOidCharacter or NULL; optional client-assigned unique identifier for the order (max 40 characters). Useful for tracking orders in automated systems.
priceCharacter or NULL; limit order price. Required for limit stop orders; must NOT be set for market stop orders. Should align with the symbol's
priceIncrement.sizeCharacter or NULL; order quantity in base currency. Required for limit stop orders. For market stop orders, mutually exclusive with
funds.fundsCharacter or NULL; order amount in quote currency for market stop orders. Mutually exclusive with
size. Not applicable for limit stop orders.stpCharacter or NULL; self-trade prevention strategy. One of
"DC"(Decrement and Cancel),"CO"(Cancel Oldest),"CN"(Cancel Newest),"CB"(Cancel Both).remarkCharacter or NULL; order remarks or notes (max 20 ASCII characters).
timeInForceCharacter or NULL; time-in-force policy for the triggered order. One of
"GTC"(Good Till Cancelled),"GTT"(Good Till Time),"IOC"(Immediate Or Cancel),"FOK"(Fill Or Kill).cancelAfterNumeric or NULL; number of seconds after which to auto-cancel. Only valid when
timeInForce = "GTT".postOnlyLogical or NULL; if
TRUE, the triggered order is rejected if it would immediately match (guarantees maker fee).hiddenLogical or NULL; if
TRUE, the triggered order is hidden from the order book.icebergLogical or NULL; if
TRUE, onlyvisibleSizeof the order is displayed.visibleSizeCharacter or NULL; the visible portion of an iceberg order. Only applicable when
iceberg = TRUE.tradeTypeCharacter; trade type, defaults to
"TRADE"for spot trading.
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with columns:
order_id(character): KuCoin-assigned stop order identifier.client_oid(character or NA): Client-provided order identifier, if supplied.
Examples
\dontrun{
stop <- KucoinStopOrders$new()
# Limit stop-loss sell order
order <- stop$add_order(
type = "limit", symbol = "BTC-USDT", side = "sell",
stopPrice = "90000", price = "89500", size = "0.00001"
)
print(order$order_id)
# Market stop-loss sell order by size
order <- stop$add_order(
type = "market", symbol = "BTC-USDT", side = "sell",
stopPrice = "90000", size = "0.00001"
)
# Market buy breakout order by funds
order <- stop$add_order(
type = "market", symbol = "BTC-USDT", side = "buy",
stopPrice = "105000", funds = "100"
)
}
Method cancel_order_by_id()
Cancel Stop Order by Order ID
Cancels a single pending stop order using its KuCoin-assigned order ID. Only stop orders that have not yet been triggered can be cancelled.
Workflow
Request: Authenticated DELETE with the order ID in the URL path.
Parsing: Returns a
data.tablewith the cancelled order ID.
Automated Trading Usage
Dynamic Stop Adjustment: Cancel and replace stop orders as price moves in your favour.
Strategy Teardown: Cancel individual stop orders when closing a position manually.
Error Recovery: Cancel stop orders that were placed with incorrect parameters.
curl
curl --location --request DELETE 'https://api.kucoin.com/api/v1/stop-order/vs8hoo8q2ceshiue003b67c0' \
--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_order_by_client_oid()
Cancel Stop Order by Client OID
Cancels a pending stop order using the client-assigned order ID and symbol.
Both clientOid and symbol are required as query parameters.
Workflow
Request: Authenticated DELETE with
clientOidandsymbolas query parameters.Parsing: Returns a
data.tablewith the cancelled order ID.
Automated Trading Usage
Client-Side Tracking: Cancel orders using your own identifiers without storing KuCoin order IDs.
Idempotent Cancellation: Use deterministic client OIDs for reliable cancel-and-replace workflows.
Multi-Symbol Bots: Combine
clientOidprefixes with symbol for organized order management.
curl
curl --location --request DELETE 'https://api.kucoin.com/api/v1/stop-order/cancelOrderByClientOid?clientOid=my-stop-001&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
clientOidCharacter; the client-assigned order ID used when placing the stop order.
symbolCharacter; trading pair symbol (e.g.,
"BTC-USDT"). Required to disambiguate client OIDs across different trading pairs.
Method cancel_all()
Cancel All Stop Orders
Cancels all pending stop orders matching the given filters. Supports filtering by symbol, trade type, and specific order IDs. If no filters are provided, all pending stop orders are cancelled.
Workflow
Request: Authenticated DELETE with optional filter query parameters.
Parsing: Returns a
data.tablewith all cancelled order IDs.
Automated Trading Usage
Emergency Kill Switch: Call with no filters to cancel all stop orders during extreme volatility.
Symbol Cleanup: Filter by
symbolto cancel all stop orders for a specific trading pair.Selective Batch Cancel: Pass
orderIdsto cancel a specific subset of stop orders.
curl
curl --location --request DELETE 'https://api.kucoin.com/api/v1/stop-order/cancel?symbol=BTC-USDT&tradeType=TRADE' \
--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
KucoinStopOrders$cancel_all(query = list())Arguments
queryNamed list; optional filter parameters:
symbol(character): Trading pair to filter by (e.g.,"BTC-USDT").tradeType(character): Trade type, typically"TRADE"for spot.orderIds(character): Comma-separated list of specific stop order IDs to cancel.
Method get_order_by_id()
Get Stop Order by Order ID
Retrieves full details for a single stop order using its KuCoin-assigned order ID. Returns order parameters, status, trigger price, and timestamps.
Workflow
Request: Authenticated GET with the order ID in the URL path.
Parsing: Returns a
data.tablewith all order fields as columns.
Automated Trading Usage
Order Verification: Confirm a stop order was placed with the correct parameters after submission.
Status Monitoring: Poll order status to detect when a stop order has been triggered.
Audit Trail: Retrieve full order details for logging and post-trade analysis.
curl
curl --location --request GET 'https://api.kucoin.com/api/v1/stop-order/vs8hoo8q2ceshiue003b67c0' \
--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": {
"id": "vs8hoo8q2ceshiue003b67c0",
"symbol": "BTC-USDT",
"userId": "60d7b4c0f1baed0006a25f12",
"type": "limit",
"side": "sell",
"price": "89500",
"size": "0.00001",
"funds": null,
"stp": null,
"timeInForce": "GTC",
"cancelAfter": -1,
"postOnly": false,
"hidden": false,
"iceberg": false,
"visibleSize": null,
"channel": "API",
"clientOid": null,
"remark": null,
"tags": null,
"stopPrice": "90000",
"stop": "loss",
"stopTriggerTime": null,
"tradeType": "TRADE",
"createdAt": 1706789012000,
"orderTime": 1706789012345678900
}
}Returns
data.table (or promise<data.table> if constructed with async = TRUE) with one row containing order details. Key columns include:
id(character): Stop order identifier.symbol(character): Trading pair (e.g.,"BTC-USDT").type(character): Order type ("limit"or"market").side(character): Order side ("buy"or"sell").price(character): Limit price (NULL for market orders).size(character): Order quantity in base currency.stop_price(character): Trigger price for the stop order.stop(character): Stop direction ("loss"or"entry").datetime_created(POSIXct): Creation datetime.
Method get_order_by_client_oid()
Get Stop Order by Client OID
Retrieves stop order details using the client-assigned order ID and symbol.
May return multiple results if the same clientOid was used across different orders.
Workflow
Request: Authenticated GET with
clientOidandsymbolas query parameters.Parsing: If multiple orders match, returns a multi-row
data.table; otherwise returns a single-rowdata.table.
Automated Trading Usage
Client-Side Lookup: Query stop orders using your own identifiers without persisting KuCoin IDs.
Order Reconciliation: Verify that a stop order with a given client OID exists and check its parameters.
Deduplication Check: Before placing a new stop order, check if one with the same client OID already exists.
curl
curl --location --request GET 'https://api.kucoin.com/api/v1/stop-order/queryOrderByClientOid?clientOid=my-stop-001&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'JSON Response
{
"code": "200000",
"data": [
{
"id": "vs8hoo8q2ceshiue003b67c0",
"symbol": "BTC-USDT",
"userId": "60d7b4c0f1baed0006a25f12",
"type": "limit",
"side": "sell",
"price": "89500",
"size": "0.00001",
"funds": null,
"stp": null,
"timeInForce": "GTC",
"cancelAfter": -1,
"postOnly": false,
"hidden": false,
"iceberg": false,
"visibleSize": null,
"channel": "API",
"clientOid": "my-stop-001",
"remark": null,
"tags": null,
"stopPrice": "90000",
"stop": "loss",
"stopTriggerTime": null,
"tradeType": "TRADE",
"createdAt": 1706789012000,
"orderTime": 1706789012345678900
}
]
}Arguments
clientOidCharacter; the client-assigned order ID to search for.
symbolCharacter; trading pair symbol (e.g.,
"BTC-USDT"). Required to scope the search to a specific trading pair.
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with one or more rows of order details. Key columns include:
id(character): Stop order identifier.symbol(character): Trading pair (e.g.,"BTC-USDT").type(character): Order type ("limit"or"market").side(character): Order side ("buy"or"sell").price(character): Limit price (NULL for market orders).size(character): Order quantity in base currency.stop_price(character): Trigger price for the stop order.client_oid(character): The client-assigned order ID.datetime_created(POSIXct): Creation datetime.
Method get_order_list()
Get Stop Order List
Retrieves a paginated list of stop orders with optional filtering by symbol,
side, type, and time range. Returns all matching stop orders as a data.table.
Workflow
Request: Authenticated GET with optional query parameters for filtering and pagination.
Parsing: Extracts the
itemsarray from the paginated response and binds rows into adata.table. Returns an emptydata.tableif no orders match.
Automated Trading Usage
Portfolio Monitoring: Periodically poll active stop orders to maintain an accurate view of pending triggers.
Reconciliation: Compare local order state with exchange state on bot startup or after reconnection.
Reporting: Retrieve historical stop orders filtered by time range for performance analysis.
curl
curl --location --request GET 'https://api.kucoin.com/api/v1/stop-order?symbol=BTC-USDT&side=sell&pageSize=50¤tPage=1' \
--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": {
"currentPage": 1,
"pageSize": 50,
"totalNum": 1,
"totalPage": 1,
"items": [
{
"id": "vs8hoo8q2ceshiue003b67c0",
"symbol": "BTC-USDT",
"userId": "60d7b4c0f1baed0006a25f12",
"type": "limit",
"side": "sell",
"price": "89500",
"size": "0.00001",
"funds": null,
"stp": null,
"timeInForce": "GTC",
"cancelAfter": -1,
"postOnly": false,
"hidden": false,
"iceberg": false,
"visibleSize": null,
"channel": "API",
"clientOid": null,
"remark": null,
"tags": null,
"stopPrice": "90000",
"stop": "loss",
"stopTriggerTime": null,
"tradeType": "TRADE",
"createdAt": 1706789012000,
"orderTime": 1706789012345678900
}
]
}
}Usage
KucoinStopOrders$get_order_list(query = list())Arguments
queryNamed list; optional filter and pagination parameters:
symbol(character): Trading pair to filter by (e.g.,"BTC-USDT").side(character): Order side filter,"buy"or"sell".type(character): Order type filter,"limit"or"market".startAt(numeric): Start time in milliseconds (UNIX epoch).endAt(numeric): End time in milliseconds (UNIX epoch).currentPage(integer): Page number for pagination (default 1).pageSize(integer): Number of results per page (default 50, max 100).tradeType(character): Trade type, typically"TRADE"for spot.orderIds(character): Comma-separated list of specific stop order IDs.
Returns
data.table (or promise<data.table> if constructed with async = TRUE) with zero or more rows. Returns an empty data.table if no
stop orders match the query. Key columns include:
id(character): Stop order identifier.symbol(character): Trading pair (e.g.,"BTC-USDT").type(character): Order type ("limit"or"market").side(character): Order side ("buy"or"sell").price(character): Limit price (NULL for market orders).size(character): Order quantity in base currency.stop_price(character): Trigger price for the stop order.stop(character): Stop direction ("loss"or"entry").time_in_force(character): Time-in-force policy.datetime_created(POSIXct): Creation datetime.
Examples
\dontrun{
stop <- KucoinStopOrders$new()
# Get all BTC-USDT stop orders
orders <- stop$get_order_list(query = list(symbol = "BTC-USDT"))
print(orders)
# Get sell stop orders with pagination
orders <- stop$get_order_list(query = list(
symbol = "BTC-USDT", side = "sell",
currentPage = 1, pageSize = 20
))
print(nrow(orders))
# Get stop orders within a time range
orders <- stop$get_order_list(query = list(
symbol = "ETH-USDT",
startAt = as.numeric(lubridate::now() - 86400) * 1000,
endAt = as.numeric(lubridate::now()) * 1000
))
}
Examples
if (FALSE) { # \dontrun{
# Synchronous
stop <- KucoinStopOrders$new()
orders <- stop$get_order_list(query = list(symbol = "BTC-USDT"))
print(orders)
# Asynchronous
stop_async <- KucoinStopOrders$new(async = TRUE)
main <- coro::async(function() {
orders <- await(stop_async$get_order_list(query = list(symbol = "BTC-USDT")))
print(orders)
})
main()
while (!later::loop_empty()) later::run_now()
} # }
## ------------------------------------------------
## Method `KucoinStopOrders$add_order`
## ------------------------------------------------
if (FALSE) { # \dontrun{
stop <- KucoinStopOrders$new()
# Limit stop-loss sell order
order <- stop$add_order(
type = "limit", symbol = "BTC-USDT", side = "sell",
stopPrice = "90000", price = "89500", size = "0.00001"
)
print(order$order_id)
# Market stop-loss sell order by size
order <- stop$add_order(
type = "market", symbol = "BTC-USDT", side = "sell",
stopPrice = "90000", size = "0.00001"
)
# Market buy breakout order by funds
order <- stop$add_order(
type = "market", symbol = "BTC-USDT", side = "buy",
stopPrice = "105000", funds = "100"
)
} # }
## ------------------------------------------------
## Method `KucoinStopOrders$cancel_order_by_id`
## ------------------------------------------------
if (FALSE) { # \dontrun{
stop <- KucoinStopOrders$new()
# Cancel a specific stop order
result <- stop$cancel_order_by_id("vs8hoo8q2ceshiue003b67c0")
print(result$cancelled_order_ids)
} # }
## ------------------------------------------------
## Method `KucoinStopOrders$cancel_order_by_client_oid`
## ------------------------------------------------
if (FALSE) { # \dontrun{
stop <- KucoinStopOrders$new()
# Cancel by client OID
result <- stop$cancel_order_by_client_oid("my-stop-001", symbol = "BTC-USDT")
print(result$cancelled_order_id)
} # }
## ------------------------------------------------
## Method `KucoinStopOrders$cancel_all`
## ------------------------------------------------
if (FALSE) { # \dontrun{
stop <- KucoinStopOrders$new()
# Cancel all stop orders for BTC-USDT
result <- stop$cancel_all(query = list(symbol = "BTC-USDT"))
print(result$cancelled_order_ids)
# Cancel all stop orders (no filter)
result <- stop$cancel_all()
print(result$cancelled_order_ids)
} # }
## ------------------------------------------------
## Method `KucoinStopOrders$get_order_by_id`
## ------------------------------------------------
if (FALSE) { # \dontrun{
stop <- KucoinStopOrders$new()
# Get stop order details
order <- stop$get_order_by_id("vs8hoo8q2ceshiue003b67c0")
print(order$stop_price)
print(order$side)
} # }
## ------------------------------------------------
## Method `KucoinStopOrders$get_order_by_client_oid`
## ------------------------------------------------
if (FALSE) { # \dontrun{
stop <- KucoinStopOrders$new()
# Look up stop order by client OID
order <- stop$get_order_by_client_oid("my-stop-001", symbol = "BTC-USDT")
print(order$id)
print(order$stop_price)
} # }
## ------------------------------------------------
## Method `KucoinStopOrders$get_order_list`
## ------------------------------------------------
if (FALSE) { # \dontrun{
stop <- KucoinStopOrders$new()
# Get all BTC-USDT stop orders
orders <- stop$get_order_list(query = list(symbol = "BTC-USDT"))
print(orders)
# Get sell stop orders with pagination
orders <- stop$get_order_list(query = list(
symbol = "BTC-USDT", side = "sell",
currentPage = 1, pageSize = 20
))
print(nrow(orders))
# Get stop orders within a time range
orders <- stop$get_order_list(query = list(
symbol = "ETH-USDT",
startAt = as.numeric(lubridate::now() - 86400) * 1000,
endAt = as.numeric(lubridate::now()) * 1000
))
} # }