Modify OCO
PUT /gttoco/modifyOco
Modifying a GTT OCO (Good Till Triggered, One-Cancels-the-Other) order involves adjusting the parameters of an existing GTT OCO order. This can include changing the trigger prices, adjusting the quantity of the order, or modifying the order types.
When modifying a GTT OCO order, investors can make changes to both legs of the OCO order, ensuring that the exit strategies remain aligned with their trading objectives and market conditions. For example, if market conditions change and the investor wants to adjust their profit target or stop-loss levels, they can modify the trigger prices accordingly.
Steps to modify a GTT OCO order :
- Retrieve all active GTT orders using the List GTT OCO API. In the 'List GTT OCO ' API response, we will get both active GTT and GTT OCO orders. To identify an OCO order, check if the 'triggers' key in the API response contains both 'stopLoss' and 'target' keys. If it does, then it is an OCO order.
- Note down the GTT summary ID of the order you wish to modify.Then, based on the parameters provided below, you can modify your order.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
exchange | string | true | The exchange remains the same as when creating the GTT OCO. It cannot be modified. |
symbolName | string | true | The symbol name remains the same as when creating the GTT OCO. It cannot be modified. |
transactionType | string | true | Determines whether the order is a buy or sell transaction. |
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 target order will enter the market. |
targetLimitPrice | string | true | Required for limit orders. The price at which the target order will be executed on the exchange. |
stoplossTriggerPrice | string | true | 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. |
gttSummaryId | number | true | Enter the gttSummaryId of the GTT OCO order you want to modify here. |
Sample Request Body
requestBody={
"exchange": "NSE",
"symbolName": "IDEA",
"transactionType": "SELL",
"quantity": "25",
"productType": "CNC",
"orderType": "L",
"targetTriggerPrice": "13.5",
"targetLimitPrice": "13.5",
"stoplossTriggerPrice": "10.5",
"stoplossLimitPrice": "10.5",
"marketProtection": "",
"gttSummaryId" : 670745
}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
curl -X PUT 'https://tradeapi.samco.in/gttoco/modifyOco' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'x-session-token: <SESSION_TOKEN>' \
-d '{"exchange":"NSE","symbolName":"IDEA","transactionType":"SELL","quantity":"25","productType":"CNC","orderType":"L","targetTriggerPrice":"13.5","targetLimitPrice":"13.5","stoplossTriggerPrice":"10.5","stoplossLimitPrice":"10.5","marketProtection":"","gttSummaryId":670745}'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": "25",
"productType": "CNC",
"orderType": "L",
"targetTriggerPrice": "13.5",
"targetLimitPrice": "13.5",
"stoplossTriggerPrice": "10.5",
"stoplossLimitPrice": "10.5",
"marketProtection": "",
"gttSummaryId": 670745
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://tradeapi.samco.in/gttoco/modifyOco"))
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("x-session-token", "<SESSION_TOKEN>")
.PUT(HttpRequest.BodyPublishers.ofString(requestBody))
.build();
HttpResponse<String> response =
client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}(async () => {
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'x-session-token': '<SESSION_TOKEN>',
};
const requestBody = {
exchange: "NSE",
symbolName: "IDEA",
transactionType: "SELL",
quantity: "25",
productType: "CNC",
orderType: "L",
targetTriggerPrice: "13.5",
targetLimitPrice: "13.5",
stoplossTriggerPrice: "10.5",
stoplossLimitPrice: "10.5",
marketProtection: "",
gttSummaryId: 670745
};
const response = await fetch('https://tradeapi.samco.in/gttoco/modifyOco', {
method: 'PUT',
headers,
body: JSON.stringify(requestBody),
});
const data = await response.json();
console.log(data);
})();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": "25",
"productType": "CNC",
"orderType": "L",
"targetTriggerPrice": "13.5",
"targetLimitPrice": "13.5",
"stoplossTriggerPrice": "10.5",
"stoplossLimitPrice": "10.5",
"marketProtection": "",
"gttSummaryId": 670745
}
r = requests.put('https://tradeapi.samco.in/gttoco/modifyOco',
data=json.dumps(requestBody),
headers=headers)
print(r.json())Sample Response
{
"serverTime": "04/04/24 13:53:23",
"msgId": "432b12e6-6acc-4b38-98b3-3940e09d0c26",
"status": "Success",
"statusMessage": "GTT MODIFIED",
"gttSummaryId": "671170",
"orderDetails": {
"transactionType": "SELL",
"orderType": "L",
"symbol": "14366_NSE",
"symbolName": "IDEA",
"productType": "CNC",
"target": {
"limitPrice": "13.5",
"triggerId": "932815",
"triggerPrice": "13.5",
"type": "TARGET",
"quantity": "25",
"marketProtection": ""
},
"stopLoss": {
"limitPrice": "10.5",
"triggerId": "932820",
"triggerPrice": "10.5",
"type": "STOPLOSS",
"quantity": "25",
"marketProtection": ""
}
}
}Response Schema
Status Code 200
| Name | Type | Description |
|---|---|---|
serverTime | string | Time at Server. |
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. It can be either 'Success' or 'Failure'. |
statusMessage | string | A message describing the result of the API call. |
gttSummaryId | string | After the order is modified, a new gttSummaryId is generated. For any further operation, this gttSummaryId will be valid for this order and the old gttSummaryId becomes invalid. |
transactionType | string | Describes whether the transaction involves buying or selling. |
orderType | string | The type of order. |
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. |
target | object | An object containing details about the target order. |
stopLoss | object | An object containing details about the stop loss order. |