Smart Orders
Automate entry and exit strategies with Smart Orders using GTT and OCO orders. This guide demonstrates creating, modifying, canceling, and managing smart orders for CASH and F&O segments.
Smart Orders help you automate entries/exits with minimal code. Two types are supported:
- GTT (Good Till Triggered): Triggers a single order when price crosses your trigger
- OCO (One Cancels the Other): Places target and stop-loss together; execution of one cancels the other
Create GTT
Create a GTT that arms a single order when your trigger condition is met.
Python SDK Usage
Parameters
| Name | Type | Description |
|---|---|---|
smart_order_type * | str | Set to GTT to create a Good-Till-Triggered smart order. Example: GTT. |
reference_id * | str | User-provided alphanumeric string (8-20 characters) that serves as an idempotency key, with at most two hyphens (-) allowed. |
segment * | str | Segment for which the order will be placed. See Segment. Examples: CASH, FNO. |
trading_symbol * | str | Trading Symbol of the instrument as defined by the exchange |
quantity * | int | Quantity for the post-trigger order. For FNO, must respect lot size. Examples: 10, 50. |
trigger_price * | str | Trigger price as a decimal string. Example: "3985.00". |
trigger_direction * | str | Direction to monitor relative to the trigger price. Examples: UP, DOWN. |
order * | dict | Post-trigger order details |
order["order_type"] * | str | Post-trigger execution order type. See Order type. Examples: LIMIT, SL. |
| order["price"] | str | Post-trigger limit price (required if order_type is LIMIT or SL). Example: "3990.00". |
order["transaction_type"] * | str | Post-trigger transaction type. See Transaction type. Examples: BUY, SELL. |
| child_legs | dict | Optional child legs for bracket orders (target/stop-loss). |
product_type * | str | Product for the post-trigger order. See Product type. Examples: CNC, MIS. |
exchange * | str | Exchange where the instrument is traded. See Exchange. Examples: NSE. |
duration * | str | Validity of the post-trigger order. See Validity. Example: DAY. |
*required parameters
Response
Schema reference: Smart Order Response (GTT).
Create OCO
Create an OCO to protect or exit positions with target and stop-loss.
Python SDK Usage
Parameters
| Name | Type | Description |
|---|---|---|
smart_order_type * | str | Set to OCO to create a One-Cancels-Other smart order (target + stop-loss). Example: OCO. |
reference_id * | str | User-provided alphanumeric string (8-20 characters) that serves as an idempotency key, with at most two hyphens (-) allowed. |
segment * | str | Segment for which the order will be placed. See Segment. Examples: FNO, CASH. |
trading_symbol * | str | Trading Symbol of the instrument as defined by the exchange |
quantity * | int | Total quantity for both legs. Must be ≤ abs(net_position_quantity). Example: 50. |
net_position_quantity * | int | Your current net position in this symbol. Used to derive leg directions and validate quantity. Example: 50. |
transaction_type * | str | Direction of protection/exit for your position. See Transaction type. Examples: BUY, SELL. |
target * | dict | Take-profit leg details |
target["trigger_price"] * | str | Take-profit trigger price (decimal string). Example: "120.50". |
target["order_type"] * | str | Order type for the target leg. See Order type. Examples: LIMIT, MARKET. |
| target["price"] | str | Target leg limit price (required if order_type = LIMIT). Example: "121.00". |
stop_loss * | dict | Stop-loss leg details |
stop_loss["trigger_price"] * | str | Stop-loss trigger price (decimal string). Example: "95.00". |
stop_loss["order_type"] * | str | Order type for the stop-loss leg. See Order type. Examples: SL, SL_M. |
| stop_loss["price"] | str | Stop-loss leg limit price (required if order_type = SL). Example: "94.50". |
product_type * | str | Product for the OCO. See Product type. Note: For OCO in cash segment, only MIS is supported currently. |
exchange * | str | Exchange for this instrument. See Exchange. Example: NSE. |
duration * | str | Validity for both legs. See Validity. Example: DAY. |
*required parameters
Important OCO orders are meant to exit an existing position.
- In the F&O segment you must already hold the contract.
- In the CASH segment, OCO is restricted to intraday (
MIS) positions.
Response
Schema reference: Smart Order Response (OCO).
Notes
quantitymust be ≤abs(net_position_quantity).- If a leg executes, the other cancels automatically.
Modify Smart Order
Modify contracts differ by flow. Only the fields listed below are honoured; everything else is ignored or rejected. Use cancel + create when you need changes outside of these lists.
Modifiable Fields - GTT
quantity- Updated order quantitytrigger_price- Updated trigger price thresholdtrigger_direction- Updated directionorder.order_type- Updated order typeorder.price- Updated limit price (required forLIMIT/SLtypes; set toNoneforMARKET/SL_M)child_legs- Updated bracket order legs (optional; all child leg fields are modifiable if provided)
Modifiable Fields - OCO
quantity- Updated order quantityduration- Updated validityproduct_type- Updated product (e.g., MIS ↔ NRML for FNO; CASH OCO only supports MIS)target.trigger_price- Updated profit target trigger pricestop_loss.trigger_price- Updated stop-loss trigger price
Modify GTT
Parameters (GTT)
| Name | Type | Description |
|---|---|---|
smart_order_id * | str | Smart order identifier. Example: gtt_91a7f4. |
smart_order_type * | str | Set to GTT (required for routing) |
segment * | str | Segment of the order (required for routing). See Segment. Examples: CASH, FNO. |
| quantity | int | Updated quantity. |
| trigger_price | str | Updated trigger price (decimal string). |
| trigger_direction | str | Updated trigger direction. Examples: UP, DOWN. |
| order["order_type"] | str | Updated order type. See Order type. |
| order["price"] | str | Updated limit price (required if order_type is LIMIT or SL; set to None for MARKET/SL_M). |
| order["transaction_type"] | str | Transaction type (required but not modifiable). See Transaction type. |
| child_legs | dict | Updated child legs for bracket orders (all child leg fields modifiable if provided). |
*required parameters
Modify OCO
Parameters (OCO)
| Name | Type | Description |
|---|---|---|
smart_order_id * | str | Smart order identifier. Example: oco_a12bc3. |
smart_order_type * | str | Set to OCO (required for routing) |
segment * | str | Segment of the order (required for routing). See Segment. Examples: FNO, CASH. |
| duration | str | Updated validity. See Validity. |
| quantity | int | Updated total quantity. |
| product_type | str | Updated product. See Product type. |
| target["trigger_price"] | str | Updated target trigger price (decimal string). |
| target["order_type"] | str | Target order type (not modifiable). See Order type. |
| target["price"] | str | Target limit price (not modifiable). |
| stop_loss["trigger_price"] | str | Updated stop-loss trigger price (decimal string). |
| stop_loss["order_type"] | str | Stop-loss order type (not modifiable). See Order type. |
| stop_loss["price"] | str | Stop-loss limit price (not modifiable). |
*required parameters
Response
Schema reference: Smart Order Response (GTT) or Smart Order Response (OCO).
Modify vs Cancel-Create
| What you need to change | GTT | OCO | Action |
|---|---|---|---|
| Quantity | ✅ Modify | ✅ Modify | Use modify |
| Trigger price | ✅ Modify | ✅ Modify (both legs) | Use modify |
| Trigger direction | ✅ Modify | N/A | Use modify |
| Order type | ✅ Modify | ❌ Not modifiable | GTT: modify; OCO: cancel+create |
| Limit price | ✅ Modify | ❌ Not modifiable | GTT: modify; OCO: cancel+create |
| Duration/validity | ❌ Not modifiable | ✅ Modify | OCO: modify; GTT: cancel+create |
| Product type | ❌ Not modifiable | ✅ Modify | OCO: modify; GTT: cancel+create |
| Symbol/contract | ❌ Not modifiable | ❌ Not modifiable | Cancel + create |
| Exchange | ❌ Not modifiable | ❌ Not modifiable | Cancel + create |
| Segment | ❌ Not modifiable | ❌ Not modifiable | Cancel + create |
| Smart order type (GTT ↔ OCO) | ❌ Not modifiable | ❌ Not modifiable | Cancel + create |
Note: When a field is marked as "Not modifiable" (❌), you must cancel the existing smart order and create a new one with the desired changes. The "N/A" designation indicates that the feature does not apply to that smart order type.
Cancel Smart Order
Cancel any active smart order.
Python SDK Usage
Parameters
| Name | Type | Description |
|---|---|---|
segment * | str | Segment of the smart order to cancel. See Segment. Examples: CASH, FNO. |
smart_order_type * | str | Smart order type. Examples: GTT, OCO. |
smart_order_id * | str | Smart order identifier. Example: gtt_91a7f4. |
*required parameters
Response
Schema reference: Smart Order Response (GTT) or Smart Order Response (OCO).
Get Smart Order
Retrieve details of a specific smart order by its internal ID.
Python SDK Usage
Parameters
| Name | Type | Description |
|---|---|---|
segment * | str | Segment of the smart order to fetch. See Segment. Examples: CASH, FNO. |
smart_order_type * | str | Smart order type. Examples: GTT, OCO. |
smart_order_id * | str | Smart order identifier. Example: gtt_91a7f4. |
*required parameters
Response
Schema reference: Smart Order Response (GTT) or Smart Order Response (OCO).
List Smart Orders
Filter and list smart orders by type, segment, status and a time window. Pagination is supported.
Python SDK Usage
Parameters
| Name | Type | Description |
|---|---|---|
| segment | str | Segment to list smart orders for. See Segment. Examples: FNO, CASH. Optional; server defaults may apply if omitted. |
| smart_order_type | str | Smart order type to list. Examples: OCO, GTT. Optional; server defaults may apply if omitted. |
| status | str | Current state filter. Examples: ACTIVE, TRIGGERED, CANCELLED, COMPLETED. Optional; server defaults may apply if omitted. |
| page | int | Page number starting from 0. Use with page_size to paginate long lists. Min: 0, Max: 500. |
| page_size | int | Number of records per page. Tune this for your UI/export. Min: 1, Max: 50. |
| start_date_time | str | Inclusive start of the time window in ISO 8601. Examples: 2025-01-16T09:15:00, 2025-01-16T00:00:00. |
| end_date_time | str | Inclusive end of the time window in ISO 8601. Must not be before start_date_time. Examples: 2025-01-16T09:15:00, 2025-01-16T00:00:00. |
Validations:
end_date_timemust not be beforestart_date_time.- Date range between
start_date_timeandend_date_timemust not exceed one month.
Tip If you expect an order that has already been triggered or cancelled, switch the
statusfilter accordingly—ACTIVEonly returns live, untriggered smart orders.
Response
| Name | Type | Description |
|---|---|---|
| orders | list | List of smart orders |
| orders[] | dict | Smart order item (GTT or OCO). See Smart Order Response (GTT) or Smart Order Response (OCO) |
Smart Order Constants
The Python SDK provides constants for smart order types, trigger directions, and statuses:
Smart Order Types
Trigger Directions
Smart Order Status
Quick Tips
- Use a unique
reference_idper new smart order to avoid accidental duplicates. - For OCO, ensure
quantity≤abs(net_position_quantity). The leg directions are derived from your net position. - All prices should be passed as decimal strings (e.g.,
"3985.00"). - Use the SDK constants (like
SMART_ORDER_TYPE_GTT) for better type safety and code clarity.
Schemas
Smart Order Response (GTT)
| Name | Type | Description |
|---|---|---|
| smart_order_id | str | Smart order identifier |
| smart_order_type | str | Smart order type. Example: GTT. |
| status | str | Smart order status (e.g., ACTIVE) |
| trading_symbol | str | Trading Symbol of the instrument as defined by the exchange |
| exchange | str | Stock exchange |
| quantity | int | Quantity |
| product_type | str | Product type |
| duration | str | Validity |
| order.order_type | str | Order type. See Order type. Examples: LIMIT, SL. |
| order.price | str | Price for LIMIT/SL |
| order.transaction_type | str | See Transaction type. Examples: BUY, SELL. |
| ltp | float | Last traded price of the instrument |
| trigger_direction | str | Trigger direction. Examples: UP, DOWN. |
| trigger_price | str | Trigger price (decimal string) |
| segment | str | Market segment |
| remark | str | Remark or status message |
| display_name | str | Display name for the instrument |
| child_legs | dict | Child legs for bracket orders (target/stop-loss) |
| is_cancellation_allowed | bool | Whether cancellation is allowed |
| is_modification_allowed | bool | Whether modification is allowed |
| created_at | str | Creation time (ISO 8601). Examples: 2025-01-16T09:15:00, 2025-01-16T00:00:00. |
| expire_at | str | Expiry time (ISO 8601). Examples: 2025-01-16T09:15:00, 2025-01-16T00:00:00. |
| triggered_at | str | Trigger time (ISO 8601). Examples: 2025-01-16T09:15:00, 2025-01-16T00:00:00. |
| updated_at | str | Last updated time (ISO 8601). Examples: 2025-01-16T09:15:00, 2025-01-16T00:00:00. |
Smart Order Response (OCO)
| Name | Type | Description |
|---|---|---|
| smart_order_id | str | Smart order identifier |
| smart_order_type | str | Smart order type. Example: OCO. |
| status | str | Smart order status (e.g., ACTIVE) |
| trading_symbol | str | Trading Symbol of the instrument as defined by the exchange |
| exchange | str | Stock exchange |
| quantity | int | Quantity of the order to be placed |
| product_type | str | Product type |
| duration | str | Validity |
| target.trigger_price | str | Target trigger price (decimal string) |
| target.order_type | str | Order type. See Order type. Examples: LIMIT, MARKET. |
| target.price | str | Target limit price |
| stop_loss.trigger_price | str | Stop-loss trigger price (decimal string) |
| stop_loss.order_type | str | Order type. See Order type. Examples: SL, SL_M. |
| stop_loss.price | str | Stop-loss limit price |
| is_cancellation_allowed | bool | Whether cancellation is allowed |
| is_modification_allowed | bool | Whether modification is allowed |
| created_at | str | Creation time (ISO 8601). Examples: 2025-01-16T09:15:00, 2025-01-16T00:00:00. |
| expire_at | str | Expiry time (ISO 8601). Examples: 2025-01-16T09:15:00, 2025-01-16T00:00:00. |
| triggered_at | str | Trigger time (ISO 8601). Examples: 2025-01-16T09:15:00, 2025-01-16T00:00:00. |
| updated_at | str | Last updated time (ISO 8601). Examples: 2025-01-16T09:15:00, 2025-01-16T00:00:00. |