Cancel OCO Order By OrderId (Implementation)
Source:R/impl_spottrading_orders_oco.R
cancel_oco_order_by_order_id_impl.Rd
Cancels an existing OCO order on the KuCoin Spot trading system using its system-generated order ID (orderId
) asynchronously by sending a DELETE request to the /api/v3/oco/order/{orderId}
endpoint.
Usage
cancel_oco_order_by_order_id_impl(
keys = get_api_keys(),
base_url = get_base_url(),
orderId,
.__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()
.- orderId
Character string; the unique order ID to cancel (e.g., "674c316e688dea0007c7b986"). Required.
Value
Promise resolving to a data.table
with one row containing:
cancelledOrderIds
(list): A list of two character strings representing the IDs of the canceled limit and stop-limit orders.
Details
What is an OCO Order?
An OCO (One-Cancels-the-Other) order pairs a limit order (profit target) with a stop-limit order (loss limit). Canceling an OCO order removes both components, which is useful when:
Strategy Adjustment: Market conditions shift, and you no longer want automated profit-taking or loss-limiting (e.g., news-driven volatility).
Manual Intervention: You decide to manage the position manually instead of relying on pre-set triggers.
Error Correction: You need to correct an OCO order placed with incorrect parameters. For instance, if you set an OCO to sell BTC at $55,000 (profit) or $48,000 (stop-loss) but BTC’s volatility decreases, you might cancel it to set tighter limits.
Description
This function initiates the cancellation of an OCO order identified by its orderId
, returning a data.table
with the IDs of the canceled limit and stop-limit orders.
Workflow
Parameter Validation: Ensures
orderId
is a non-empty string.Request Construction: Constructs the endpoint URL by embedding
orderId
as a path parameter.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, confirms success ("200000"), and converts the
cancelledOrderIds
array to adata.table
column as a list.
API Details
Endpoint:
DELETE https://api.kucoin.com/api/v3/oco/order/{orderId}
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: cancelOcoOrderByOrderId
Official Documentation: KuCoin Cancel OCO Order By OrderId
Request
Examples
if (FALSE) { # \dontrun{
library(coro)
library(data.table)
main_async <- coro::async(function() {
# Cancel an OCO order by orderId
canceled_orders <- await(cancel_oco_order_by_order_id_impl(
orderId = "674c316e688dea0007c7b986"
))
print(canceled_orders)
})
# Run the async function
main_async()
while (!later::loop_empty()) later::run_now()
} # }