Cancel Order
Cancel a single open order by its order id, from any client language.
https://apix.stocksdeveloper.in/trading/cancelOrderByPlatformId The Cancel Order call cancels an open order using its order id. It works the same way across every supported broker, so you write the call once. The same function is available in HTTP REST, Python, Java, C#, Excel, AmiBroker, and MetaTrader. It returns true on success and false otherwise.
This call cancels an open order using its order id. It is available in HTTP REST, Python, Java, C#, Excel, AmiBroker, and MetaTrader.
For related calls, see Cancel All Orders and Cancel Child Orders.
Code samples
HTTP
Example
curl https://apix.stocksdeveloper.in/trading/cancelOrderByPlatformId \
-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_order_by_platform_id(self, \
pseudo_account, platform_id):Example
response = autotrader.cancel_order_by_platform_id( \
'XX1234', '201007000438034')
if response.success():
print("Result: {0}".format(response.result))
else:
print("Message: {0}".format(response.message))Java
Signature
/**
* Cancels an order.
*
* @param pseudoAccount pseudo account
* @param platformId platform id (id given to order by trading platform)
* @return <code>true</code> on success, <code>false</code> otherwise
*/
IOperationResponse<Boolean> cancelOrderByPlatformId(
String pseudoAccount, String platformId);Example
// Places an order
final IOperationResponse<String> response =
autotrader.placeRegularOrder("ACC_NAME", "<exchange>", "SBIN",
TradeType.BUY, OrderType.LIMIT, ProductType.INTRADAY,
20, 180f, 0f);
// Read order id
String orderId = null;
if (response.success()) {
orderId = response.getResult();
} else {
final String errorMessage = response.getMessage();
}
// Somewhere later in your code
// Cancel the order
autotrader.cancelOrderByPlatformId("ACC_NAME", orderId);C#
Signature
/// <summary>
/// Cancels an order. For more information, please see
/// <a href="https://stocksdeveloper.in/documentation/api/cancel-order/">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?> CancelOrderByPlatformId(
string pseudoAccount, string platformId);Example
// Places an order
IOperationResponse<string> response =
autotrader.PlaceRegularOrder("ACC_NAME",
"<exchange>", "SBIN", TradeType.BUY, OrderType.LIMIT,
ProductType.INTRADAY, 10, 100.5f, 0f);
// Read order id
string orderId = null;
if (response.Success())
{
orderId = response.Result;
}
else
{
string errorMessage = response.Message;
}
// Somewhere later in your code
// Cancel the order
IOperationResponse<bool?> response =
autoTrader.CancelOrderByPlatformId(
"XX1234", "200831101595372");
if(response.Success()) {
Console.WriteLine("Result: {0}", response.Result);
}
else {
Console.WriteLine("Message: {0}", response.Message);
}Excel
Signature
Public Function CancelOrder(PseudoAccount As String, _
OrderId As String) As BooleanExample
Dim OrderId As String
OrderId = PlaceOrder("ACC_NAME", _
"<exchange>", "SBIN", "BUY", "LIMIT", _
"INTRADAY", 100, 200.55, 0)
' Somewhere later in your code,
' when you want to cancel this order
' Cancel the order
CancelOrder("ACC_NAME", OrderId);AmiBroker
Signature
function cancelOrder(account, orderId)Example
orderId = placeOrder(AT_ACCOUNT,
AT_EXCHANGE, AT_SYMBOL, "BUY",
"LIMIT", AT_PRODUCT_TYPE, AT_QUANTITY,
buyPrice, defaultTriggerPrice(), 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 cancel this order
// Read orderId from static variable
orderId = readStaticVariableText(AT_ACCOUNT, "ORDER_ID");
// Cancel the order
cancelOrder(AT_ACCOUNT, orderId);This cancels the order if it is still open. Some variables above are parameters defined by the AutoTrader library.
MetaTrader
Signature
bool cancelOrder(string account, string orderId)Example
string orderId = placeOrder(AT_ACCOUNT,
AT_EXCHANGE, "SBIN", SELL, LIMIT, INTRADAY, 1,
192.44, 0.0, true);
// You can even store the orderId
// in a static variable
// Somewhere later in your code,
// when you want to cancel this order
cancelOrder(AT_ACCOUNT, orderId);This cancels the order if it is still open. Some variables above are parameters defined by the MetaTrader library.
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 | 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 every open order for an account in one call, see Cancel All Orders. To exit a bracket or cover order, see Cancel Child Orders.
Thanks for the feedback. Still stuck? Contact support.
Last updated 21 June 2026