• Home
  • Products
    • Login
    • Product Info
    • User Guide
    • Pricing
  • Services
    • Stock Brokers
    • Freelancers
  • Help
    • Documentation
    • Knowledge Base
    • FAQ
  • Company
    • About Us
    • Contact Us
    • Terms & Conditions
  • Home
  • Products
    • Login
    • Product Info
    • User Guide
    • Pricing
  • Services
    • Stock Brokers
    • Freelancers
  • Help
    • Documentation
    • Knowledge Base
    • FAQ
  • Company
    • About Us
    • Contact Us
    • Terms & Conditions

AutoTrader Web

home/Documentation/AutoTrader Web
Expand All Collapse All
  • Index
  • Getting Started
  • Portfolio Management System (PMS)
  •  Copy Trading (Master-Child Auto-Copy)
    • Master-Child Copy - Performance
  • PMS vs Master-Child
  • Trading View
  •  Supported Brokers
    • Symphony XTS
    • Zerodha
    • Angel Broking
    • Dhan
    • Aliceblue
    • Fyers
    • Nuvama
    • IIFL
    • Zebu
    • Finvasia
    • Motilal Oswal
    • Kotak
    • Mastertrust
    • Five Paisa
    • Choice Broking
    • FlatTrade
    • Tradejini
    • Upstox
    • SAS Online
    • Profitmart
  •  Client Setup
    • Desktop Client
    • AmiBroker Library
    • Excel Library or Tools
    • Java Library
    • MetaTrader Library
    • C# Library
    • Python Library
    • HTTP REST
  •  User Interface
    • User Registration
    •   Settings
      • General
      • Trading Accounts
      • Pseudo Accounts
      • Group Accounts
      • API Key
    •   AutoTrader
      • Activity
      • Instruments
    •   Trading
      • Summary
      • Positions
      • Orders
      • Margins
      • Holdings
      • Trade
    •   User
      • Account
      • Profile
  •  API (Application Programming Interface)
    • Place Regular Order
    • Place Cover Order
    • Place Bracket Order
    • Place Advanced Order
    • Cancel Order
    • Cancel Child Orders
    • Cancel All Orders
    • Modify Order
    • Modify Order Price
    • Modify Order Quantity
    • Square-off Position
    • Square-off Portfolio
    • Read Orders
    • Read Positions
    • Read Margins
    • Read Holdings
    • Read Portfolio Summary
    • Fetch All Trading Accounts
    • Create or Update Trading Account
    • Validate Trading Account Credentials
    • API Parameters
    • API Rate Limits
    • Email Limits
    • Postman
  • Pricing
  • Precautions
  •  Broker Independence
    • API Functions
    • Pseudo Account
    • Instruments (Trading Symbols)
  • Quantity Multiplier
  • Architecture

Cancel Order

2650 views August 12, 2021 Pritesh 10

API function to cancel an open order. APIs are available in AmiBroker, MetaTrader, Excel, Java, C#, Python, HTTP REST.

Api function will cancel an order on Supports leading Indian Stock Brokers.

  • AmiBroker
  • MetaTrader
  • Java
  • C#
  • Python
  • HTTP
  • Excel
  • Postman

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 will cancel the order (if it is open).

Some variables used in above code are parameters defined by AutoTrader library.

Signature

bool cancelOrder(string account, string orderId)

Example

string orderId = placeOrder(AT_ACCOUNT, 
    NSE, "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 will cancel the order (if it is open).

Some variables used in above code are parameters defined by AutoTrader library.

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", "NSE", "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);

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", 
	"NSE", "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);
}

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))

Example

curl https://api.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"
}

Signature

Public Function CancelOrder(PseudoAccount As String, _
        OrderId As String) As Boolean

Example

Dim OrderId As String
 
OrderId = PlaceOrder("ACC_NAME", _
    "NSE", "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);

Postman is widely used tool for API testing. We have provided below a collection of all of our APIs in postman collection format. Click postman collection to know more about how to use it.


Parameters

AmiBroker, Excel, MetaTrader

  • account – pseudo account
  • orderId – publisherId (orderId given by placeOrder*() function)

Java, HTTP, C#, Python

  • account – pseudo account
  • orderId – platformId (orderId given by placeOrder*() function)

Return value

AmiBroker, Excel, MetaTrader

This function sends a cancel order request to AutoTrader Desktop Client. On successful submission, it will return True, otherwise False

Java, HTTP, C#, Python

Returns a response object, with result being True on success, False otherwise.

The type of the return value is Boolean.

Place Advanced Order
Cancel Child Orders

Was this helpful?

10 Yes  1 No
Related Articles
  • Master-Child Copy – Performance
  • Tradejini
  • Dhan
  • FlatTrade
  • Supported Brokers
  • Symphony XTS

© 2025 Stocks Developer. All Rights Reserved.