Batch Cancel Stop Orders (Implementation)
Source:R/impl_spottrading_orders_stop.R
cancel_stop_order_batch_impl.Rd
Cancels a batch of stop orders on the KuCoin Spot trading system asynchronously by sending a DELETE request to the /api/v1/stop-order/cancel
endpoint.
Returns a data.table
with the IDs of the canceled stop orders.
Usage
cancel_stop_order_batch_impl(
keys = get_api_keys(),
base_url = get_base_url(),
query = list(),
.__coro_env_parent__ = <environment>
)
Arguments
- keys
List; API configuration parameters from
get_api_keys()
. Defaults toget_api_keys()
.- base_url
Character string; base URL for the KuCoin API. Defaults to
get_base_url()
.- query
Named list; optional query parameters for filtering (e.g.,
list(symbol = "ETH-BTC", orderIds = "5bd6e9286d99522a52e458de,5bd6e9286d99522a52e458df")
).
Value
Promise resolving to a data.table
with one row containing:
cancelledOrderIds
(list): A list of character strings representing the IDs of the canceled stop orders.
Details
What is a Stop Order and Batch Cancellation?
A stop order is a conditional order that triggers a market or limit order when a specified price (stop price) is reached, commonly used for:
Loss Limiting: Sell an asset if its price drops to a threshold (e.g., sell BTC at $48,000 if it falls from $50,000).
Breakout Trading: Buy an asset if its price rises past a resistance level (e.g., buy BTC at $52,000 if it breaks $51,000). Batch cancellation allows you to cancel multiple stop orders at once, which is useful for:
Portfolio Adjustment: Clear all stop orders for a symbol (e.g., "BTC-USDT") if market conditions shift unexpectedly.
Strategy Reset: Cancel outdated stop orders across multiple pairs or IDs when refining your trading plan.
Risk Management: Remove pending stops during high volatility to avoid unintended triggers (e.g., canceling stops on ETH-BTC during a flash crash). For example, if you have stop orders at $48,000 and $47,000 for BTC-USDT but anticipate a rally, batch canceling them prevents premature sales.
Description
This function cancels multiple stop orders using optional filters (symbol
, tradeType
, orderIds
) via a DELETE request, returning the canceled order IDs in a data.table
.
Workflow
Parameter Validation: Ensures
query
is a named list, validatessymbol
if provided, and checkstradeType
enum.Request Construction: Builds the endpoint URL with query parameters (
symbol
,tradeType
,orderIds
) usingbuild_query
.Authentication: Generates private API headers using
build_headers()
with the DELETE method and endpoint.API Request: Sends a DELETE request to the KuCoin API with a 3-second timeout via
httr::DELETE
.Response Processing: Parses the response with
process_kucoin_response
, confirms success ("200000"), and converts thecancelledOrderIds
array to adata.table
column as a list.
API Details
Endpoint:
DELETE https://api.kucoin.com/api/v1/stop-order/cancel
Domain: Spot
API Channel: Private
API Permission: Spot
Rate Limit Pool: Spot
Rate Limit Weight: 3
SDK Service: Spot
SDK Sub-Service: Order
SDK Method Name: batchCancelStopOrder
Official Documentation: KuCoin Batch Cancel Stop Orders
Request
Query Parameters
symbol
: String (optional) - Filter by trading pair symbol (e.g., "ETH-BTC"). Cancels all stop orders for this symbol if specified.tradeType
: Enum(optional) - Transaction type: "TRADE" (Spot), "MARGIN_TRADE" (Cross Margin), "MARGIN_ISOLATED_TRADE" (Isolated Margin). Defaults to "TRADE". orderIds
: String (optional) - Comma-separated list of stop order IDs (e.g., "5bd6e9286d99522a52e458de,5bd6e9286d99522a52e458df").
Examples
if (FALSE) { # \dontrun{
library(coro)
library(data.table)
main_async <- coro::async(function() {
# Batch cancel stop orders for ETH-BTC
canceled_orders <- await(cancel_stop_order_batch_impl(
query = list(
symbol = "ETH-BTC",
tradeType = "TRADE",
orderIds = "5bd6e9286d99522a52e458de,5bd6e9286d99522a52e458df"
)
))
print(canceled_orders)
})
# Run the async function
main_async()
while (!later::loop_empty()) later::run_now()
} # }