• 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 Portfolio

2242 views April 24, 2025 Pritesh 3

API function to square-off portfolio (account). The system will filter all OPEN positions present in given portfolio (account) and send a square-off position request for each. APIs are available in AmiBroker, MetaTrader, Excel, Java, C#, Python, HTTP REST.

Note: This function should ideally be used when you want exit all open positions. For example, an intraday trader may want to square-off portfolio before auto-square-off time set by the broker.

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

Updates: This api was upgraded to automatically cancel all open orders for the given portfolio 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 account.
* Server will square-off all open positions in the given account.
*
* pseudoAccount - account to which the position belongs
* category - position category (DAY, NET). Pass NET if you are not sure.
*/
function squareOffPortfolio(pseudoAccount, category) 

Examples

// Square-off all positions in account ABC123
squareOffPortfolio("ABC123", "NET");

// Square-off all positions in account
// defined in chart parameters
squareOffPortfolio(AT_ACCOUNT, "NET");

Signature

/**
* Submits a square-off request for the given account.
* Server will square-off all open positions in the given account.
*
* pseudoAccount - account to which the position belongs
* category - position category (DAY, NET). Pass NET if you are not sure.
*/
bool squareOffPortfolio(string pseudoAccount, string category)

Example

// Square-off all positions in account ABC123
squareOffPortfolio("ABC123", "NET");

// Square-off all positions in account
// defined in chart parameters
squareOffPortfolio(AT_ACCOUNT, "NET");

Signature

/**
 * Submits a square-off portfolio request.
 *
 * @param pseudoAccount pseudo account
 * @param category      position category (DAY or NET portfolio to consider)
 * @param cancelOpenOrders        cancel all open orders for the given position 
 * @return true on successful acceptance of square-off request, false otherwise
 */
IOperationResponse<Boolean> squareOffPortfolio(
	final String pseudoAccount, 
	final PositionCategory category,
    final boolean cancelOpenOrders));

Example

IOperationResponse<Boolean> response = 
	autotrader.squareOffPortfolio(
		"ABC123", PositionCategory.NET, true);

Signature

/// <summary>
/// Submits a square-off portfolio request.
/// </summary>
/// <param name="pseudoAccount"> pseudo account </param>
/// <param name="category">      position category (DAY or NET portfolio to consider) </param>
/// <returns> true on successful acceptance of square-off request, false otherwise </returns>
IOperationResponse<bool?> SquareOffPortfolio(
	string pseudoAccount, PositionCategory category);

Example

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

Signature

def square_off_portfolio(self, \
	pseudo_account, position_category):

Example

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

Example

curl https://api.stocksdeveloper.in/trading/squareOffPortfolio \
   -H "api-key: <your_api_key>" \
   -d "pseudoAccount=ACC_NAME" \
   -d "category=NET" \
   -d "cancelOpenOrders=true"

Response

{
    "result":true,
    "error":null,
    "message":null,
    "status":true,
    "commandId":"9f8b5738-c1aa-4623-b0c5-8df779e0f44d"
}

Signature

' Submits a square-off request for the given account.
' Server will square-off all open positions in the given account.
'
' pseudoAccount - account to which the position belongs
' category - position category (DAY, NET). Pass NET if you are not sure.
Public Function SquareOffPortfolio(pseudoAccount As String, _ 
	category As String) As Boolean

Example

' Square-off all OPEN positions in account ABC123
SquareOffPortfolio("ABC123", "NET")

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
Square-off Position
Read Orders

Was this helpful?

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

© 2025 Stocks Developer. All Rights Reserved.