Get OCO Order Detail By OrderId (Implementation)
Source:R/impl_spottrading_orders_oco.R
get_oco_order_detail_by_order_id_impl.Rd
Retrieves detailed information about an OCO order, including its associated limit and stop-limit orders, using its system-generated order ID (orderId
) from the KuCoin Spot trading system asynchronously by sending a GET request to the /api/v3/oco/order/details/{orderId}
endpoint.
Usage
get_oco_order_detail_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 retrieve (e.g., "674c3b6e688dea0007c7bab2"). Required.
Value
Promise resolving to a data.table
with one row containing:
orderId
(character): Unique order ID generated by the KuCoin system.symbol
(character): Trading pair symbol (e.g., "BTC-USDT").clientOid
(character): Client-assigned order ID.orderTime
(integer): Order placement time in milliseconds.status
(character): Order status ("NEW", "DONE", "TRIGGERED", "CANCELED").orders
(list): List of nested objects, each containing:id
(character): Individual order ID.symbol
(character): Trading pair symbol.side
(character): Order side ("buy" or "sell").price
(character): Order price.stopPrice
(character): Trigger price.size
(character): Order quantity.status
(character): Order status ("NEW", etc.).
Details
What is an OCO Order?
An OCO order links a limit order (e.g., profit target) with a stop-limit order (e.g., loss limit), canceling one when the other executes. Fetching detailed info is useful for:
Execution Analysis: Review the specific prices and sizes of both orders to evaluate strategy effectiveness.
Debugging: Confirm the stop and limit prices align with your intended trade plan (e.g., catching setup errors).
Performance Tracking: Assess whether triggers are nearing execution in volatile conditions. For example, detailed info on an OCO order at $50,000 for BTC might show a limit at $55,000 and a stop at $48,000, helping you adjust if the range is too wide.
Description
This function fetches detailed OCO order information (orderId
, symbol
, clientOid
, orderTime
, status
, and orders
array) and returns it in a data.table
with nested order details as a list column.
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 GET method and endpoint.API Request: Sends a GET request to the KuCoin API with a 3-second timeout via
httr::GET
.Response Processing: Parses the response, confirms success ("200000"), and constructs a
data.table
withorders
as a list column.
API Details
Endpoint:
GET https://api.kucoin.com/api/v3/oco/order/details/{orderId}
Domain: Spot
API Channel: Private
API Permission: General
Rate Limit Pool: Spot
Rate Limit Weight: 2
SDK Service: Spot
SDK Sub-Service: Order
SDK Method Name: getOcoOrderDetailByOrderId
Official Documentation: KuCoin Get OCO Order Detail By OrderId
Request
Response
Data Schema
code
: String (required) - Response code ("200000" indicates success).data
: Object (required) - Contains:orderId
: String (required) - System-generated order ID.symbol
: String (required) - Trading pair symbol.clientOid
: String (required) - Client-assigned order ID.orderTime
: Integer(required) - Order placement time in milliseconds. status
: String (required) - Order status: "NEW", "DONE", "TRIGGERED", "CANCELED".orders
: ArrayObject (required) - List of associated orders (limit and stop-limit), each with:id
: String - Individual order ID.symbol
: String - Trading pair symbol.side
: String - Order side ("buy" or "sell").price
: String - Order price.stopPrice
: String - Trigger price.size
: String - Order quantity.status
: String - Order status.
JSON Response Example
{
"code": "200000",
"data": {
"orderId": "674c3b6e688dea0007c7bab2",
"symbol": "BTC-USDT",
"clientOid": "5c52e1203aa6f37f1e493fb",
"orderTime": 1733049198863,
"status": "NEW",
"orders": [
{
"id": "vs93gpqc7dn6h3fa003sfelj",
"symbol": "BTC-USDT",
"side": "buy",
"price": "94000.00000000000000000000",
"stopPrice": "94000.00000000000000000000",
"size": "0.10000000000000000000",
"status": "NEW"
},
{
"id": "vs93gpqc7dn6h3fa003sfelk",
"symbol": "BTC-USDT",
"side": "buy",
"price": "96000.00000000000000000000",
"stopPrice": "98000.00000000000000000000",
"size": "0.10000000000000000000",
"status": "NEW"
}
]
}
}
Examples
if (FALSE) { # \dontrun{
library(coro)
library(data.table)
main_async <- coro::async(function() {
# Retrieve detailed OCO order by orderId
oco_detail <- await(get_oco_order_detail_by_order_id_impl(
orderId = "674c3b6e688dea0007c7bab2"
))
print(oco_detail)
})
# Run the async function
main_async()
while (!later::loop_empty()) later::run_now()
} # }