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
| Name | Type | Required | Description |
|---|---|---|---|
exchange | string | true | Name 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. |
symbolName | string | true | Symbol name of the scrip. For Equity, enter SymbolName of the scrip. For Derivatives, enter TradingSymbol of the scrip. |
transactionType | string | true | Determines whether the order is a buy or sell transaction. EQ delivery buy orders are not allowed in GTT. |
quantity | string | true | Defines the number of units or shares of the asset to be bought or sold. |
productType | string | true | Product type of the order. Can be CNC (Cash and Carry) or NRML (Normal). |
orderType | string | true | Type of order placed. Can be MKT (Market Order) or L (Limit Order). |
targetTriggerPrice | string | true | The price at which the order will enter the market. |
targetLimitPrice | string | true | Required for limit orders. The price at which the order will be executed on the exchange. |
stoplossTriggerPrice | string | false | The price at which the stop-loss order will enter the market. |
stoplossLimitPrice | string | true | Required for limit orders. The price at which the stop-loss order will be executed on the exchange. |
marketProtection | string | true | Required 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
| Name | Type | Description |
|---|---|---|
serverTime | string | The time when the server processed the request. |
msgId | string | 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. |
status | string | The status of the API response. Possible values: 'Success', 'Error', or 'Failure'. |
statusMessage | string | A message describing the result of the API call. |
gttSummaryId | string | Uniquely identifies the GTT order, essential for modifying, retrieving status, and deleting. |
transactionType | string | Determines whether the order is a buy or sell transaction. |
symbol | string | The actual name of the symbol for the scrip. |
symbolName | string | The name of the symbol representing the scrip. |
productType | string | The product type of the order. |
orderType | string | The type of order. |
target | object | An object containing details about the target order. |
stopLoss | object | An object containing details about the stop-loss order. |
quantity | string | The number of units to be traded. |
triggerPrice | string | The price at which the target order will be triggered. |
limitPrice | string | The maximum price at which the order will be executed. |
marketProtection | string | An object containing details about the market protection. |
type | string | The "TARGET" type indicates a target order, while "STOPLOSS" signifies a stop-loss order. |
triggerId | string | An identifier for the trigger. |