Square-off Portfolio

Exit all open positions in a single trading account with one call.

POST https://apix.stocksdeveloper.in/trading/squareOffPortfolio
WriteReturns true on success7 languagesBroker independent
In short

The Square-off Portfolio call exits all OPEN positions in a single trading account. The system finds every OPEN position in the account and sends a square-off request for each one. You can also cancel all open orders first by passing `cancelOpenOrders`. It works the same way across AmiBroker, MetaTrader, Excel, Java, C#, Python and HTTP REST, and returns true on success.

Use this call when you want to exit all open positions in an account at once. For example, an intraday trader may want to square off the full portfolio before the broker’s auto-square-off time. This call works with leading Indian stock brokers; see the full list on the supported brokers page. To exit a single position instead of the whole account, use Square-off Position.

This call cancels all open orders for the account before it starts the square-off. A parameter named cancelOpenOrders controls this behaviour.

Code samples

Samples

HTTP

Example

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

Python

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

Java

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

C#

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

Excel

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

AmiBroker

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) 

Example 1

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

Square-off all open positions in a named account.

Example 2

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

Square-off using the account defined in chart parameters.

MetaTrader

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 1

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

Square-off all open positions in a named account.

Example 2

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

Square-off using the account defined in chart parameters.

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

ParameterDescription
accountnickname of the broker account (also known as pseudo account)
categoryposition category

Return value

DirectJava · C# · Python · HTTP

The call returns the order id given by your trading platform.

BridgeExcel · AmiBroker · MetaTrader

The call returns the library order id. The Desktop Client passes the request on to your broker.

Notes

To exit a single position instead, use Square-off Position. To check order status, use Read Orders.

Was this page helpful?

Last updated 21 June 2026