Cancel OCO Order By ClientOid (Implementation)
Source:R/impl_spottrading_orders_oco.R
cancel_oco_order_by_client_oid_impl.Rd
Cancels an existing OCO order on the KuCoin Spot trading system using its client-assigned order ID (clientOid
) asynchronously by sending a DELETE request to the /api/v3/oco/client-order/{clientOid}
endpoint.
Usage
cancel_oco_order_by_client_oid_impl(
keys = get_api_keys(),
base_url = get_base_url(),
clientOid,
.__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()
.- clientOid
Character string; the unique client order ID to cancel (e.g., "5c52e11203aa67f1e493fb"). 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 links a limit order (profit target) with a stop-limit order (loss limit). Canceling by clientOid
allows:
Custom Tracking: Use your unique ID to cancel without needing the system
orderId
, ideal for systems tracking orders locally.Flexibility: Adjust strategies when market trends shift unexpectedly (e.g., canceling an OCO if a breakout is anticipated).
Error Handling: Quickly remove an OCO order if set incorrectly, such as wrong price levels. For example, if an OCO order was placed with a
clientOid
to sell BTC at $55,000 or $48,000 but you detect a potential rally, you might cancel it using your custom ID.
Description
This function initiates the cancellation of an OCO order identified by its clientOid
, returning a data.table
with the IDs of the canceled limit and stop-limit orders.
Workflow
Parameter Validation: Ensures
clientOid
is a non-empty string.Request Construction: Constructs the endpoint URL by embedding
clientOid
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/client-order/{clientOid}
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: cancelOcoOrderByClientOid
Official Documentation: KuCoin Cancel OCO Order By ClientOid
Request
Examples
if (FALSE) { # \dontrun{
library(coro)
library(data.table)
main_async <- coro::async(function() {
# Cancel an OCO order by clientOid
canceled_orders <- await(cancel_oco_order_by_client_oid_impl(
clientOid = "5c52e11203aa67f1e493fb"
))
print(canceled_orders)
})
# Run the async function
main_async()
while (!later::loop_empty()) later::run_now()
} # }