BinanceOcoOrders: OCO Order Management
BinanceOcoOrders: OCO Order Management
Details
Provides methods for placing, cancelling, and querying OCO (One-Cancels-Other) orders on Binance. Inherits from BinanceBase.
Purpose and Scope
OCO Placement: Place OCO orders combining a limit and a stop-loss.
OCO Cancellation: Cancel an entire OCO order list by ID.
OCO Queries: Retrieve a specific OCO, all open OCOs, or historical OCOs.
Super class
binance::BinanceBase -> BinanceOcoOrders
Methods
Inherited methods
Method add_oco_order()
Place an OCO Order
Places a new OCO (One-Cancels-Other) order on Binance. An OCO combines a limit order and a stop-loss (or stop-loss-limit) order.
Official Documentation
Binance New OCO Verified: 2026-03-10
Usage
BinanceOcoOrders$add_oco_order(
symbol,
side,
quantity,
price,
stopPrice,
stopLimitPrice = NULL,
stopLimitTimeInForce = NULL,
listClientOrderId = NULL,
limitClientOrderId = NULL,
stopClientOrderId = NULL,
limitIcebergQty = NULL,
stopIcebergQty = NULL,
newOrderRespType = NULL,
selfTradePreventionMode = NULL,
recvWindow = NULL
)Arguments
symbolCharacter; trading pair (e.g.,
"BTCUSDT").sideCharacter;
"BUY"or"SELL".quantityNumeric; base asset quantity.
priceNumeric; price for the limit leg.
stopPriceNumeric; trigger price for the stop-loss leg.
stopLimitPriceNumeric or NULL; limit price for the stop-loss-limit leg.
stopLimitTimeInForceCharacter or NULL; time-in-force for the stop-limit leg (
"GTC","IOC","FOK"). Required ifstopLimitPriceis provided.listClientOrderIdCharacter or NULL; unique ID for the entire OCO list.
limitClientOrderIdCharacter or NULL; unique ID for the limit leg.
stopClientOrderIdCharacter or NULL; unique ID for the stop-loss leg.
limitIcebergQtyNumeric or NULL; iceberg quantity for the limit leg.
stopIcebergQtyNumeric or NULL; iceberg quantity for the stop-loss leg.
newOrderRespTypeCharacter or NULL;
"ACK","RESULT", or"FULL".selfTradePreventionModeCharacter or NULL.
recvWindowInteger or NULL; max 60000.
Returns
data.table with one row per child order (long format) and the following columns:
order_list_id(integer): OCO order list identifier (repeated per child order).contingency_type(character): Always"OCO".list_status_type(character): Status type (e.g.,"EXEC_STARTED").list_order_status(character): Order status (e.g.,"EXECUTING").list_client_order_id(character): Client-assigned list ID.transact_time(POSIXct): Transaction time.symbol(character): Trading pair from parent OCO.order_symbol(character): Trading pair from child order.order_id(integer): Child order ID.client_order_id(character): Child order client ID.order_reports(list): List of order report objects (kept as list-column).
Method cancel_oco_order()
Cancel an OCO Order
Cancels an entire OCO order list by order list ID or client order ID.
Official Documentation
Binance Cancel OCO Verified: 2026-03-10
JSON Response
{
"orderListId": 0,
"contingencyType": "OCO",
"listStatusType": "ALL_DONE",
"listOrderStatus": "ALL_DONE",
"listClientOrderId": "C3wyj4WVEktd7u9aVBRXcN",
"transactTime": 1563417480525,
"symbol": "BTCUSDT",
"orders": [
{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"clientOrderId": "bfYPSQdLoqAJeNrOr9adzq"
},
{
"symbol": "BTCUSDT",
"orderId": 12569099454,
"clientOrderId": "0NPFMfBo6cMGlwnSfzBrdg"
}
],
"orderReports": [
{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"orderListId": 0,
"clientOrderId": "bfYPSQdLoqAJeNrOr9adzq",
"transactTime": 1563417480525,
"price": "55000.00000000",
"origQty": "0.00010000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT_MAKER",
"side": "SELL"
},
{
"symbol": "BTCUSDT",
"orderId": 12569099454,
"orderListId": 0,
"clientOrderId": "0NPFMfBo6cMGlwnSfzBrdg",
"transactTime": 1563417480525,
"price": "48500.00000000",
"origQty": "0.00010000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "STOP_LOSS_LIMIT",
"side": "SELL",
"stopPrice": "49000.00000000"
}
]
}Usage
BinanceOcoOrders$cancel_oco_order(
symbol,
orderListId = NULL,
listClientOrderId = NULL,
recvWindow = NULL
)Arguments
symbolCharacter; trading pair (e.g.,
"BTCUSDT").orderListIdInteger or NULL; the OCO order list ID.
listClientOrderIdCharacter or NULL; the client order list ID.
recvWindowInteger or NULL; max 60000.
Returns
data.table with one row per child order (long format) and the following columns:
order_list_id(integer): OCO order list identifier (repeated per child order).contingency_type(character): Always"OCO".list_status_type(character): Status type (e.g.,"ALL_DONE").list_order_status(character): Order status (e.g.,"ALL_DONE").list_client_order_id(character): Client-assigned list ID.transact_time(POSIXct): Cancellation time (if present).symbol(character): Trading pair from parent OCO.order_symbol(character): Trading pair from child order.order_id(integer): Child order ID.client_order_id(character): Child order client ID.
Method get_oco_order()
Query an OCO Order
Retrieves details for a specific OCO order by order list ID or original client order ID.
Official Documentation
Binance Query OCO Verified: 2026-03-10
JSON Response
{
"orderListId": 0,
"contingencyType": "OCO",
"listStatusType": "ALL_DONE",
"listOrderStatus": "ALL_DONE",
"listClientOrderId": "C3wyj4WVEktd7u9aVBRXcN",
"transactionTime": 1563417480525,
"symbol": "BTCUSDT",
"orders": [
{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"clientOrderId": "bfYPSQdLoqAJeNrOr9adzq"
},
{
"symbol": "BTCUSDT",
"orderId": 12569099454,
"clientOrderId": "0NPFMfBo6cMGlwnSfzBrdg"
}
]
}Usage
BinanceOcoOrders$get_oco_order(
orderListId = NULL,
origClientOrderId = NULL,
recvWindow = NULL
)Arguments
orderListIdInteger or NULL; the OCO order list ID.
origClientOrderIdCharacter or NULL; the original client order list ID.
recvWindowInteger or NULL; max 60000.
Returns
data.table with one row per child order (long format) and the following columns:
order_list_id(integer): OCO order list identifier (repeated per child order).contingency_type(character): Always"OCO".list_status_type(character): Status type (e.g.,"ALL_DONE").list_order_status(character): Order status.list_client_order_id(character): Client-assigned list ID.transaction_time(POSIXct): Transaction time (if present).symbol(character): Trading pair from parent OCO.order_symbol(character): Trading pair from child order.order_id(integer): Child order ID.client_order_id(character): Child order client ID.
Method get_open_oco_orders()
Get Open OCO Orders
Retrieves all currently open OCO order lists.
Official Documentation
Binance Query Open OCO Verified: 2026-03-10
JSON Response
[
{
"orderListId": 31,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "wuB13fmulKj3YjdqWEcsnp",
"transactionTime": 1565246080644,
"symbol": "LTCBTC",
"orders": [
{
"symbol": "LTCBTC",
"orderId": 4,
"clientOrderId": "r3EH2N76dHfLoSZWIUw1bT"
},
{
"symbol": "LTCBTC",
"orderId": 5,
"clientOrderId": "Cv1SnyPD3qhqpbjpYEHbd2"
}
]
}
]Returns
data.table with one row per child order across all open OCOs (long format).
Columns include:
order_list_id(integer): OCO order list identifier (repeated per child order).contingency_type(character): Always"OCO".list_status_type(character): Status type.list_order_status(character): Order status.list_client_order_id(character): Client-assigned list ID.transaction_time(POSIXct): Transaction time.symbol(character): Trading pair from parent OCO.order_symbol(character): Trading pair from child order.order_id(integer): Child order ID.client_order_id(character): Child order client ID.
Method get_all_oco_orders()
Get All OCO Orders
Retrieves all OCO order lists (open, cancelled, done). If fromId is set,
returns OCOs with order list ID >= that value. Otherwise returns the most
recent OCOs.
Official Documentation
Binance Query All OCO Verified: 2026-03-10
JSON Response
[
{
"orderListId": 29,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "amEEAXryFzFwYF1FeRpUoZ",
"transactionTime": 1565245913483,
"symbol": "LTCBTC",
"orders": [
{
"symbol": "LTCBTC",
"orderId": 4,
"clientOrderId": "oD7aesZqjEGlZrbtRpy5zB"
},
{
"symbol": "LTCBTC",
"orderId": 5,
"clientOrderId": "Jr1h6xirOxgeJOUuYQS7V3"
}
]
},
{
"orderListId": 30,
"contingencyType": "OCO",
"listStatusType": "ALL_DONE",
"listOrderStatus": "ALL_DONE",
"listClientOrderId": "XbijSrMBk4cGLvoDYtU08w",
"transactionTime": 1565245913847,
"symbol": "BTCUSDT",
"orders": [
{
"symbol": "BTCUSDT",
"orderId": 8,
"clientOrderId": "pO9ufTiFGg3ndn3Kq7BuSA"
},
{
"symbol": "BTCUSDT",
"orderId": 9,
"clientOrderId": "TXOvglzXuaubXAaENpaRCB"
}
]
}
]Usage
BinanceOcoOrders$get_all_oco_orders(
fromId = NULL,
startTime = NULL,
endTime = NULL,
limit = NULL,
recvWindow = NULL
)Arguments
fromIdInteger or NULL; pagination cursor (orderListId).
startTimeInteger or NULL; start timestamp in milliseconds.
endTimeInteger or NULL; end timestamp in milliseconds.
limitInteger or NULL; max results (default 500, max 1000).
recvWindowInteger or NULL; max 60000.
Returns
data.table with one row per child order across all OCOs (long format).
Columns include:
order_list_id(integer): OCO order list identifier (repeated per child order).contingency_type(character): Always"OCO".list_status_type(character): Status type.list_order_status(character): Order status.list_client_order_id(character): Client-assigned list ID.transaction_time(POSIXct): Transaction time.symbol(character): Trading pair from parent OCO.order_symbol(character): Trading pair from child order.order_id(integer): Child order ID.client_order_id(character): Child order client ID.
Examples
if (FALSE) { # \dontrun{
# Synchronous
oco <- BinanceOcoOrders$new()
result <- oco$add_oco_order(
symbol = "BTCUSDT", side = "SELL",
quantity = 0.0001, price = 55000, stopPrice = 49000,
stopLimitPrice = 48500, stopLimitTimeInForce = "GTC"
)
print(result)
# Asynchronous
oco_async <- BinanceOcoOrders$new(async = TRUE)
main <- coro::async(function() {
result <- await(oco_async$get_open_oco_orders())
print(result)
})
main()
while (!later::loop_empty()) later::run_now()
} # }
## ------------------------------------------------
## Method `BinanceOcoOrders$add_oco_order`
## ------------------------------------------------
if (FALSE) { # \dontrun{
oco <- BinanceOcoOrders$new()
result <- oco$add_oco_order(
symbol = "BTCUSDT", side = "SELL",
quantity = 0.0001, price = 55000, stopPrice = 49000,
stopLimitPrice = 48500, stopLimitTimeInForce = "GTC"
)
print(result)
} # }
## ------------------------------------------------
## Method `BinanceOcoOrders$cancel_oco_order`
## ------------------------------------------------
if (FALSE) { # \dontrun{
oco <- BinanceOcoOrders$new()
cancelled <- oco$cancel_oco_order("BTCUSDT", orderListId = 0)
print(cancelled)
} # }
## ------------------------------------------------
## Method `BinanceOcoOrders$get_oco_order`
## ------------------------------------------------
if (FALSE) { # \dontrun{
oco <- BinanceOcoOrders$new()
order <- oco$get_oco_order(orderListId = 0)
print(order)
} # }
## ------------------------------------------------
## Method `BinanceOcoOrders$get_open_oco_orders`
## ------------------------------------------------
if (FALSE) { # \dontrun{
oco <- BinanceOcoOrders$new()
open <- oco$get_open_oco_orders()
print(open)
} # }
## ------------------------------------------------
## Method `BinanceOcoOrders$get_all_oco_orders`
## ------------------------------------------------
if (FALSE) { # \dontrun{
oco <- BinanceOcoOrders$new()
all <- oco$get_all_oco_orders(limit = 50)
print(all)
} # }