Skip to content

Add OCO

POST /gttoco/addOco

Add OCO refers to the functionality of adding an OCO (One-Cancels-the-Other) condition to a GTT (Good Till Triggered) order. With this feature, investors can set up two separate exit conditions for a single position. If one condition is triggered and the corresponding order is executed, the other order is automatically canceled, hence the "one-cancels-the-other" concept.

Here’s how it works?

  • Let’s say you are holding a stock in your portfolio and you have kept a target and stoploss in mind for exiting this stock.
  • You can place a GTT OCO order and Enter your target trigger and stoploss trigger along with respective order prices. Once you’ve entered your target and stoploss prices, our system will start monitoring the market.
  • If the price of your stock reaches your target price, our system will automatically place a sell order with target price for you. In this scenario, your stoploss trigger will get canceled automatically.
  • If the price of your stock reaches your stoploss price, our system will automatically place a sell order with stoploss price for you. In this scenario, your target trigger will get canceled automatically. Read More....

In the BFO exchange, only SENSEX and BANKEX trades are allowed.

Parameters

NameTypeRequiredDescription
exchangestringtrueName of the exchange. Valid values: BSE, NSE, NFO, BFO, MFO, MCX, CDS. Default is NSE if not provided. Mandatory for BSE, NFO, BFO, MFO, CDS, and MCX.
symbolNamestringtrueSymbol name of the scrip. For Equity, enter SymbolName of the scrip. For Derivatives, enter TradingSymbol of the scrip.
transactionTypestringtrueDetermines whether the order is a buy or sell transaction. EQ delivery buy orders are not allowed in GTT.
quantitystringtrueDefines the number of units or shares of the asset to be bought or sold.
productTypestringtrueProduct type of the order. Can be CNC (Cash and Carry) or NRML (Normal).
orderTypestringtrueType of order placed. Can be MKT (Market Order) or L (Limit Order).
targetTriggerPricestringtrueThe price at which the order will enter the market.
targetLimitPricestringtrueRequired for limit orders. The price at which the order will be executed on the exchange.
stoplossTriggerPricestringfalseThe price at which the stop-loss order will enter the market.
stoplossLimitPricestringtrueRequired for limit orders. The price at which the stop-loss order will be executed on the exchange.
marketProtectionstringtrueRequired for market orders. Default is set to 3% to protect the order from potential market losses.

Sample Request Body

json
requestBody={
  "exchange": "NSE", 
  "symbolName": "IDEA", 
  "transactionType": "SELL", 
  "quantity": "1", 
  "productType": "NRML",
  "orderType": "L", 
  "targetTriggerPrice": "14.5",
  "targetLimitPrice": "15",
  "stoplossTriggerPrice": "13.95",
  "stoplossLimitPrice": "12.90"
}
json
requestBody={
  "exchange": "NSE", 
  "symbolName": "IDEA", 
  "transactionType": "SELL", 
  "quantity": "1", 
  "productType": "NRML",
  "orderType": "MKT", 
  "targetTriggerPrice": "14.5",
  "stoplossTriggerPrice": "13.95",
  "marketProtection": ""
}

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/gttoco/addOco' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'x-session-token: <SESSION_TOKEN>' \
  -d '{"exchange":"NSE","symbolName":"IDEA","transactionType":"SELL","quantity":"1","productType":"NRML","orderType":"L","targetTriggerPrice":"14.5","targetLimitPrice":"15","stoplossTriggerPrice":"13.95","stoplossLimitPrice":"12.90"}'
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 = """
        {
          "exchange": "NSE",
          "symbolName": "IDEA",
          "transactionType": "SELL",
          "quantity": "1",
          "productType": "NRML",
          "orderType": "L",
          "targetTriggerPrice": "14.5",
          "targetLimitPrice": "15",
          "stoplossTriggerPrice": "13.95",
          "stoplossLimitPrice": "12.90"
        }
        """;

    HttpClient client = HttpClient.newHttpClient();

    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://tradeapi.samco.in/gttoco/addOco"))
        .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 = {
    exchange: "NSE",
    symbolName: "IDEA",
    transactionType: "SELL",
    quantity: "1",
    productType: "NRML",
    orderType: "L",
    targetTriggerPrice: "14.5",
    targetLimitPrice: "15",
    stoplossTriggerPrice: "13.95",
    stoplossLimitPrice: "12.90"
  };

  const response = await fetch('https://tradeapi.samco.in/gttoco/addOco', {
    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 = {
  "exchange": "NSE",
  "symbolName": "IDEA",
  "transactionType": "SELL",
  "quantity": "1",
  "productType": "NRML",
  "orderType": "L",
  "targetTriggerPrice": "14.5",
  "targetLimitPrice": "15",
  "stoplossTriggerPrice": "13.95",
  "stoplossLimitPrice": "12.90"
}

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

print(r.json())

Sample response

json
{
    "serverTime": "29/05/24 18:54:01",
    "msgId": "505b7b1b-f3d9-4597-86ac-cb0accc21898",
    "status": "Failure",
    "statusMessage": "Failure",
    "orderDetails": {
        "transactionType": "SELL",
        "symbol": "14366_NSE",
        "symbolName": "IDEA-EQ",
        "productType": "NRML",
        "orderType": "L",
        "target": {
            "quantity": "1",
            "triggerPrice": "14.5",
            "limitPrice": "15",
            "marketProtection": "",
            "type": "TARGET",
            "triggerId": "0"
        },
        "stopLoss": {
            "quantity": "1",
            "triggerPrice": "13.95",
            "limitPrice": "12.90",
            "marketProtection": "",
            "type": "STOPLOSS",
            "triggerId": "0"
        }
    }
}
json
{
    "serverTime": "29/05/24 18:51:12",
    "msgId": "8f7d196b-c432-43fb-a2b3-34e134d00035",
    "status": "Failure",
    "statusMessage": "Failure",
    "orderDetails": {
        "transactionType": "SELL",
        "symbol": "14366_NSE",
        "symbolName": "IDEA-EQ",
        "productType": "NRML",
        "orderType": "MKT",
        "target": {
            "quantity": "1",
            "triggerPrice": "14.5",
            "limitPrice": "",
            "marketProtection": "3",
            "type": "TARGET",
            "triggerId": "0"
        },
        "stopLoss": {
            "quantity": "1",
            "triggerPrice": "13.95",
            "limitPrice": "",
            "marketProtection": "3",
            "type": "STOPLOSS",
            "triggerId": "0"
        }
    }
}

Response Schema

Status Code 200

NameTypeDescription
serverTimestringThe time when the server processed the request.
msgIdstringA unique identifier for every request into the system. Please quote this identifier to the support team if you face issues with the API request.
statusstringThe status of the API response. Possible values: 'Success', 'Error', or 'Failure'.
statusMessagestringA message describing the result of the API call.
gttSummaryIdstringUniquely identifies the GTT order, essential for modifying, retrieving status, and deleting.
transactionTypestringDetermines whether the order is a buy or sell transaction.
symbolstringThe actual name of the symbol for the scrip.
symbolNamestringThe name of the symbol representing the scrip.
productTypestringThe product type of the order.
orderTypestringThe type of order.
targetobjectAn object containing details about the target order.
stopLossobjectAn object containing details about the stop-loss order.
quantitystringThe number of units to be traded.
triggerPricestringThe price at which the target order will be triggered.
limitPricestringThe maximum price at which the order will be executed.
marketProtectionstringAn object containing details about the market protection.
typestringThe "TARGET" type indicates a target order, while "STOPLOSS" signifies a stop-loss order.
triggerIdstringAn identifier for the trigger.