Get OCO Order By OrderId (Implementation)
Source:R/impl_spottrading_orders_oco.R
get_oco_order_by_order_id_impl.Rd
Retrieves basic information about an OCO order 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/{orderId}
endpoint.
Usage
get_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 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").
Details
What is an OCO Order?
An OCO order combines a limit order (e.g., to take profits) with a stop-limit order (e.g., to limit losses), canceling one when the other executes. Retrieving this info is useful for:
Status Monitoring: Check if the order is "NEW", "TRIGGERED", or "CANCELED" to assess its current state.
Trade Review: Confirm order details like symbol and placement time match your strategy.
Decision Making: Use status to decide whether to adjust or cancel (e.g., if still "NEW" during a trend shift). For example, checking an OCO order placed at $50,000 for BTC might show it’s still "NEW", prompting a tighter stop if volatility rises.
Description
This function fetches basic OCO order details (orderId
, symbol
, clientOid
, orderTime
, status
) and returns them in a data.table
.
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 converts the
data
object to adata.table
.
API Details
Endpoint:
GET https://api.kucoin.com/api/v3/oco/order/{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: getOcoOrderByOrderId
Official Documentation: KuCoin Get OCO Order By OrderId
Request
Response
Data Schema
code
: String (required) - Response code ("200000" indicates success).data
: Object (required) - Contains:symbol
: String (required) - Trading pair symbol.clientOid
: String (required) - Client-assigned order ID.orderId
: String (required) - System-generated order ID.orderTime
: Integer(required) - Order placement time in milliseconds. status
: Enum(required) - Order status: "NEW", "DONE", "TRIGGERED", "CANCELED".
Examples
if (FALSE) { # \dontrun{
library(coro)
library(data.table)
main_async <- coro::async(function() {
# Retrieve OCO order by orderId
oco_order <- await(get_oco_order_by_order_id_impl(
orderId = "674c3b6e688dea0007c7bab2"
))
print(oco_order)
})
# Run the async function
main_async()
while (!later::loop_empty()) later::run_now()
} # }