Cancel Child Orders
Exit an open bracket or cover order by cancelling its child orders, from any client language.
https://apix.stocksdeveloper.in/trading/cancelChildOrdersByPlatformId The Cancel Child Orders call exits an open bracket or cover order. You pass the parent order id, and the system cancels its stoploss child orders. Your broker then cancels the matching target order and squares off the position at market price. It is available in HTTP REST, Python, Java, C#, Excel, AmiBroker, and MetaTrader, and it returns true on success.
This call exits an open bracket order or cover order position. It is available in HTTP REST, Python, Java, C#, Excel, AmiBroker, and MetaTrader.
For related calls, see Cancel Order and Cancel All Orders.
How it works
When you place a bracket or cover order (the parent order) and it gets executed, one or more child orders are generated. These are your stoploss and/or target orders.
This function accepts a parent order id and cancels its children:
- Find all stoploss child orders.
- Cancel them.
After the stoploss child orders are cancelled:
- The matching target order is cancelled by your stock broker (for a bracket order).
- The position is squared off at market price by your stock broker.
You see the same behaviour when you do this directly on your trading platform. So the cancel child order function is also called the exit bracket or cover order function.
Code samples
HTTP
Example
curl https://apix.stocksdeveloper.in/trading/cancelChildOrdersByPlatformId \
-H "api-key: <your-api-key>" \
-d "pseudoAccount=ACC_NAME" \
-d "platformId=<order_id>"Response
{
"result":true,
"error":null,
"message":null,
"status":true,
"commandId":"6d4b5738-c1aa-4623-b0c5-8df779e0f44d"
}Python
Signature
def cancel_child_orders_by_platform_id( \
self, pseudo_account, platform_id):Example
response = autotrader.cancel_child_orders_by_platform_id( \
'XX1234', '201007000448051')
if response.success():
print("Result: {0}".format(response.result))
else:
print("Message: {0}".format(response.message))Java
Signature
/**
* Used for exiting an open Bracket order or Cover order position. Cancels the
* child orders for the given parent order.
*
* @param pseudoAccount pseudo account
* @param platformId platform id (id given to order by trading platform)
* @return true on success, false otherwise
*/
IOperationResponse<Boolean> cancelChildOrdersByPlatformId(
String pseudoAccount, String platformId);Example
// Places an order
final IOperationResponse<String> response = autotrader
.placeBracketOrder("ACC_NAME", "<exchange>", "SBIN",
TradeType.BUY, OrderType.LIMIT,
10, 180.5f, 0f, 5f, 2.5f, 1f);
// Read order id
String orderId = null;
if (response.success()) {
orderId = response.getResult();
} else {
final String errorMessage = response.getMessage();
}
// Somewhere later in your code
// Exit the order
autotrader.cancelChildOrdersByPlatformId("ACC_NAME", orderId);C#
Signature
/// <summary>
/// Used for exiting an open Bracket order or Cover order position. Cancels the
/// child orders for the given parent order. For more information, please see
/// <a href=
/// "https://stocksdeveloper.in/documentation/api/cancel-child-orders/">api
/// docs</a>.
/// </summary>
/// <param name="pseudoAccount"> pseudo account </param>
/// <param name="platformId"> platform id (id given to order by trading platform) </param>
/// <returns> <code>true</code> on success, <code>false</code> otherwise </returns>
IOperationResponse<bool?> CancelChildOrdersByPlatformId(
string pseudoAccount, string platformId);Example
// Places an order
IOperationResponse<string> response =
autotrader.PlaceBracketOrder("ACC_NAME",
"<exchange>", "SBIN", TradeType.BUY, OrderType.LIMIT,
10, 180.5f, 0f, 5f, 2.5f, 1f);
// Read order id
string orderId = null;
if (response.Success())
{
orderId = response.Result;
}
else
{
string errorMessage = response.Message;
}
// Somewhere later in your code
// Exit the order
IOperationResponse<bool?> response =
autoTrader.CancelChildOrdersByPlatformId(
"XX1234", "200831000170161");
if(response.Success()) {
Console.WriteLine("Result: {0}", response.Result);
}
else {
Console.WriteLine("Message: {0}", response.Message);
}Excel
Signature
Public Function CancelOrderChildren(PseudoAccount As String, _
OrderId As String) As BooleanExample
Dim OrderId As String
OrderId = PlaceBracketOrder("ACC_NAME", _
"<exchange>", "SBIN", "BUY", "LIMIT", 1, _
200.55, 0, 3, 2, 1)
' Somewhere later in your code,
' when you want to exit this order
' Exit the order
CancelOrderChildren("ACC_NAME", OrderId);AmiBroker
Signature
/*
* Cancels child orders of a bracket or cover order.
* This function is useful for exiting from bracket and cover order.
* Pass the account & id you received after placing a bracket or cover order.
*/
function cancelOrderChildren(account, id)
/*
* Cancels or exits from order. This function is useful for exiting from bracket and cover order.
* If the order is OPEN, it will be cancelled. If it is executed, system will cancel it's child orders;
* which will result in exiting the position.
* Pass account & id you received after placing a bracket or cover order.
*/
function cancelOrExitOrder(account, id)Example
orderId = placeBracketOrder(AT_ACCOUNT,
AT_EXCHANGE, AT_SYMBOL, "BUY",
"LIMIT", AT_QUANTITY, buyPrice,
defaultTriggerPrice(), 5, 3, 1, True);
// You can save this orderId in a static variable
saveStaticVariableText(AT_ACCOUNT, "ORDER_ID", orderId);
// Somewhere later in your code,
// when you want to exit this order
// Read orderId from static variable
orderId = readStaticVariableText(AT_ACCOUNT, "ORDER_ID");
// Exit the order
cancelOrderChildren(AT_ACCOUNT, orderId);MetaTrader
Signature
/*
* Cancels child orders of a bracket or cover order.
* This function is useful for exiting from bracket and cover order.
* Pass the account & id you received after placing a bracket or cover order.
* Returns true on success.
*/
bool cancelOrderChildren(string account, string id)
/*
* Cancels or exits from order. This function is useful for exiting from bracket and cover order.
* If the order is OPEN, it will be cancelled. If it is executed, system will cancel it's child orders;
* which will result in exiting the position.
* Pass account & id you received after placing a bracket or cover order.
*/
bool cancelOrExitOrder(string account, string id)Example
string orderId = placeBracketOrder(AT_ACCOUNT,
AT_EXCHANGE, AT_SYMBOL, BUY, LIMIT, 1,
192, 0.0, 5, 3, 1, true);
// You can even store the orderId
// in a static variable
// Somewhere later in your code,
// when you want to exit this order
cancelOrderChildren(AT_ACCOUNT, orderId);Postman
Postman is a widely used tool for API testing. We provide a collection of all our APIs in Postman collection format. See the Postman collection guide to learn how to use it.
Parameters
| Parameter | Description |
|---|---|
| account | nickname of the broker account (also known as pseudo account) |
| orderId | parent order id given by the placeOrder*() function. AmiBroker, Excel and MetaTrader use the publisherId; Java, HTTP, C# and Python use the platformId. |
Return value
The call returns the order id given by your trading platform.
The call returns the library order id. The Desktop Client passes the request on to your broker.
Notes
To cancel a single open order, see Cancel Order. To cancel every open order for an account, see Cancel All Orders.
Thanks for the feedback. Still stuck? Contact support.
Last updated 21 June 2026