• 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

Square-off Position

6297 views April 24, 2025 Pritesh 5

API function to square-off a position. The system will validate the position to make sure it is OPEN and proceed with square-off. This command can square-off all types of positions (MIS, NRML, CNC, BO, CO). APIs are available in AmiBroker, MetaTrader, Excel, Java, C#, Python, HTTP REST.

Note: A user should ideally square-off a position with a reverse order. This function is used for special use-cases when the user wants to square-off and does not want to enter a new position for the given symbol. For example, an intraday trader may want to square-off position before auto-square-off time set by the broker.

Api function will square-off a position on Supports leading Indian Stock Brokers.

Updates: This api was upgraded to automatically cancel any open orders for the given position before starting square-off. A parameter was recently added named ‘cancelOpenOrders’.

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

Signature

/**
* Submits a square-off request for the given position.
*
* pseudoAccount - account to which the position belongs
* category - position category (DAY, NET). Pass NET if you are not sure.
* type - position type (MIS, NRML, CNC, BO, CO) 
* independentExchange - broker independent exchange
* independentSymbol - broker independent symbol
*/
function squareOffPosition(pseudoAccount, category, type, 
	independentExchange, independentSymbol)

Examples

// Square-off intraday NSE-SBIN position for account 
// defined in chart parameters
squareOffPosition(AT_ACCOUNT, "NET", "MIS", 
		"NSE", "SBIN");

// Square-off a bracket order NSE-SBIN 
// position for account defined in chart parameters
squareOffPosition(AT_ACCOUNT, "NET", "BO", 
		"NSE", "SBIN");

// Square-off delivery BSE-DMART position for account 
// defined in chart parameters
squareOffPosition(AT_ACCOUNT, "NET", "MIS", 
		"BSE", "DMART");

// Square-off NSE-BANKNIFTY future position for account ABC123
squareOffPosition("ABC123", "NET", "MIS", 
		"NSE", "BANKNIFTY_29-OCT-2020_FUT");

Signature

/**
* Submits a square-off request for the given position.
*
* pseudoAccount - account to which the position belongs
* category - position category (DAY, NET). Pass NET if you are not sure.
* type - position type (MIS, NRML, CNC, BO, CO) 
* exchange - broker independent exchange (Enum)
* independentSymbol - broker independent symbol
*/
bool squareOffPosition(string pseudoAccount, string category, 
	string type, Exchange exchange, string independentSymbol)

Examples

// Square-off intraday NSE-SBIN position for account 
// defined in chart parameters
squareOffPosition(AT_ACCOUNT, "NET", "MIS", 
		NSE, "SBIN");

// Square-off delivery BSE-DMART position for account 
// defined in chart parameters
squareOffPosition(AT_ACCOUNT, "NET", "MIS", 
		BSE, "DMART");

// Square-off NSE-BANKNIFTY future position for account ABC123
squareOffPosition("ABC123", "NET", "MIS", 
		NSE, "BANKNIFTY_29-OCT-2020_FUT");

Signature

/**
 * Submits a square-off position request.
 *
 * @param pseudoAccount pseudo account
 * @param category      position category
 * @param type          position type
 * @param exchange      position exchange (broker independent exchange)
 * @param symbol        position symbol (broker independent symbol)
 * @param cancelOpenOrders        cancel all open orders for the given position 
 * @return true on successful acceptance of square-off request, false otherwise
 */
IOperationResponse<Boolean> squareOffPosition(
		final String pseudoAccount, 
		final PositionCategory category,
		final PositionType type, 
		final String exchange, final String symbol, 
        final boolean cancelOpenOrders);

Examples

IOperationResponse<Boolean> response = 
	autotrader.squareOffPosition(ABC123, 
		PositionCategory.NET,
		PositionType.MIS, "NSE", "SBIN", true);

Signature

/// <summary>
/// Submits a square-off position request.
/// </summary>
/// <param name="pseudoAccount"> pseudo account </param>
/// <param name="category">      position category </param>
/// <param name="type">          position type </param>
/// <param name="exchange">      position exchange (broker independent exchange) </param>
/// <param name="symbol">        position symbol (broker independent symbol) </param>
/// <returns> true on successful acceptance of square-off request, false otherwise </returns>
IOperationResponse<bool?> SquareOffPosition(
	string pseudoAccount, PositionCategory category, 
	PositionType type, string exchange, string symbol);

Example

IOperationResponse<bool?> response = 
	autoTrader.SquareOffPosition(
	"XX1234", PositionCategory.NET,
	PositionType.CO, "NSE", "SBIN");
	
if(response.Success()) {
    Console.WriteLine("Result: {0}", response.Result);
}
else {
    Console.WriteLine("Message: {0}", response.Message);
}

Signature

def square_off_position(self, pseudo_account, \
	position_category, position_type, exchange, symbol):

Example

response = autotrader.square_off_position( \
	'XX1234', 'NET', 'MIS', 'NSE', 'WIPRO')
	
if response.success():
    print("Result: {0}".format(response.result))
else:
    print("Message: {0}".format(response.message))

Examples

curl https://api.stocksdeveloper.in/trading/squareOffPosition \
   -H "api-key: <your_api_key>" \
   -d "pseudoAccount=ACC_NAME" \
   -d "category=NET" \
   -d "type=MIS" \
   -d "exchange=NSE" \
   -d "symbol=SBIN" \
   -d "cancelOpenOrders=true"

curl https://api.stocksdeveloper.in/trading/squareOffPosition \
   -H "api-key: <your_api_key>" \
   -d "pseudoAccount=ACC_NAME" \
   -d "category=NET" \
   -d "type=BO" \
   -d "exchange=NSE" \
   -d "symbol=DMART"
   
curl https://api.stocksdeveloper.in/trading/squareOffPosition \
   -H "api-key: <your_api_key>" \
   -d "pseudoAccount=ACC_NAME" \
   -d "category=NET" \
   -d "type=NRML" \
   -d "exchange=NSE" \
   -d "symbol=BANKNIFTY_29-OCT-2020_FUT"

Response

{
    "result":true,
    "error":null,
    "message":null,
    "status":true,
    "commandId":"6d4b5738-c1aa-1543-b0c5-8df779e0f44d"
}

Signature

' Submits a square-off request for the given position.
'
' pseudoAccount - account to which the position belongs
' category - position category (DAY, NET). Pass NET if you are not sure.
' type - position type (MIS, NRML, CNC, BO, CO) 
' independentExchange - broker independent exchange
' independentSymbol - broker independent symbol
Public Function SquareOffPosition(pseudoAccount As String, _ 
	category As String, posType As String, independentExchange As String, _
	independentSymbol As String) As Boolean

Examples

' Square-off intraday NSE-SBIN position for account 
' defined in chart parameters
SquareOffPosition(AT_ACCOUNT, "NET", "MIS", _
	"NSE", "SBIN")

' Square-off delivery BSE-DMART position for account 
' defined in chart parameters
SquareOffPosition(AT_ACCOUNT, "NET", "MIS", _
	"BSE", "DMART")

' Square-off NSE-BANKNIFTY future position for account ABC123
SquareOffPosition("ABC123", "NET", "MIS", _
	"NSE", "BANKNIFTY_29-OCT-2020_FUT");

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

  • account – pseudo account
  • category – position category
  • type – position type
  • exchange – instrument (stock/derivative) exchange
  • symbol – instrument (stock/derivative) symbol

Internal Working

It is extremely important that users understand how AutoTrader Web’s square-off works. The details are given on Square-off process.

Admin

The internal working is explained in detail on .

Warning

This feature is fairly stable, but it might not work in rare scenarios. See details below:

Admin

There are 60 different scenarios which needs to be tested in live market.

  • 3 Exchanges (NSE, BSE, MCX)
  • 4 Brokers (Zerodha, Upstox, Finvasia, AliceBlue)
  • 5 Position types (MIS, NRML, CNC, BO, CO)

Which makes a total of (5 * 4 * 3) = 60 scenarios.

Unfortunately, it is not possible to test all of these scenarios in such a short span of time with the limited resources that we have.

We have built this feature with fail-safe. It will stop subsequent executions after first failure. This is extremely important to safeguard our clients. See below scenario:

  • Clients strategy sends square-off request
  • AutoTrader places square-off order
  • Square-off fails (most likely due to multiplier issue, as some broker give net quantity not in multiples of lot size)
  • Clients strategy sends square-off requests again as it sees the position is still open
    • But AutoTrader will not place another square-off order. Because it will result in a loop and there will be one square-off order for each function call by client’s strategy.

As you can understand, the results could be disastrous. Hence we have added a check which will stop square-off execution for a given position after first failure.

We will keep an eye on all failures and make necessary changes to the system.

Modify Order Quantity
Square-off Portfolio

Was this helpful?

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

© 2025 Stocks Developer. All Rights Reserved.