Skip to content

Position Square Off

POST /position/squareOff

SqareOff existing position. Mostly used in day trading, in which user buy or sell a particular quantity of a stock and later in the day reverse the transaction to earn a profit.

Parameters

NameTypeRequiredDescription
positionSquareOffRequestListArraytrueList of position square-off requests
exchangeStringtrueExchange code (e.g., NSE, BSE)
symbolNameStringtrueSymbol name (e.g., TCS, INFY)
productTypeStringtrueProduct type (e.g., MIS)
netQuantityStringtrueNet quantity of the position
transactionTypeStringtrueTransaction type (e.g., BUY, SELL)

Sample Request Body

json
requestBody={

  "positionSquareOffRequestList": [
    {
      "exchange": "NSE",
      "symbolName": "TCS",
      "productType": "MIS",
      "netQuantity": "250",
      "transactionType": "BUY"
    },
    {
      "exchange": "BSE",
      "symbolName": "INFY",
      "productType": "MIS",
      "netQuantity": "25",
      "transactionType": "SELL"
    }
  ]
}

Live trading endpoint

This sample sends a real request against your trading account. Replace <SESSION_TOKEN> and review every field before running — Samco does not provide a sandbox, and any successful call affects live positions and balances.

Sample Code

bash
curl -X POST 'https://tradeapi.samco.in/position/squareOff' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'x-session-token: <SESSION_TOKEN>' \
  -d '{"positionSquareOffRequestList":[{"exchange":"NSE","symbolName":"TCS","productType":"MIS","netQuantity":"250","transactionType":"BUY"},{"exchange":"BSE","symbolName":"INFY","productType":"MIS","netQuantity":"25","transactionType":"SELL"}]}'
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Sample {
  public static void main(String[] args) throws Exception {
    String requestBody = """
        {
          "positionSquareOffRequestList": [
            {
              "exchange": "NSE",
              "symbolName": "TCS",
              "productType": "MIS",
              "netQuantity": "250",
              "transactionType": "BUY"
            },
            {
              "exchange": "BSE",
              "symbolName": "INFY",
              "productType": "MIS",
              "netQuantity": "25",
              "transactionType": "SELL"
            }
          ]
        }
        """;

    HttpClient client = HttpClient.newHttpClient();

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://tradeapi.samco.in/position/squareOff"))
        .header("Content-Type", "application/json")
        .header("Accept", "application/json")
        .header("x-session-token", "<SESSION_TOKEN>")
        .POST(HttpRequest.BodyPublishers.ofString(requestBody))
        .build();

    HttpResponse<String> response =
        client.send(request, HttpResponse.BodyHandlers.ofString());
    System.out.println(response.body());
  }
}
js
(async () => {
  const headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'x-session-token': '<SESSION_TOKEN>',
  };

  const requestBody = {
    positionSquareOffRequestList: [
      {
        exchange: "NSE",
        symbolName: "TCS",
        productType: "MIS",
        netQuantity: "250",
        transactionType: "BUY"
      },
      {
        exchange: "BSE",
        symbolName: "INFY",
        productType: "MIS",
        netQuantity: "25",
        transactionType: "SELL"
      }
    ]
  };

  const response = await fetch('https://tradeapi.samco.in/position/squareOff', {
    method: 'POST',
    headers,
    body: JSON.stringify(requestBody),
  });

  const data = await response.json();
  console.log(data);
})();
py
import requests
import json

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'x-session-token': '<SESSION_TOKEN>',
}

requestBody = {
  "positionSquareOffRequestList": [
    {
      "exchange": "NSE",
      "symbolName": "TCS",
      "productType": "MIS",
      "netQuantity": "250",
      "transactionType": "BUY"
    },
    {
      "exchange": "BSE",
      "symbolName": "INFY",
      "productType": "MIS",
      "netQuantity": "25",
      "transactionType": "SELL"
    }
  ]
}

r = requests.post('https://tradeapi.samco.in/position/squareOff',
  data=json.dumps(requestBody),
  headers=headers)

print(r.json())

Sample Responses

json
{
  "serverTime": "12/12/19 16:20:11",
  "msgId": "786cdd94-2fc9-4c38-8f14-672ec64dd032",
  "positionSquareOffResponseList": [
    {
      "serverTime": "12/12/19 16:20:11",
      "msgId": "786cdd94-2fc9-4c38-8f14-672ec64dd032",
      "status": "Success",
      "statusMessage": "Request successful"
    }
  ]
}

Response Schema

Status Code 200

NameTypeDescription
serverTimeStringTime at Server.
msgIdStringThis is a unique identifier for every request into the system. Please quote this identifier to the support team if you face issues with the API request.
positionSquareOffResponseListArrayList of the PositionSquareOff end of the day.
statusStringResponse status. Can be Success or Failure.
statusMessageStringStatus Message.