How to Place Bracket Orders via API

Hi Delta Exchange Team,

I am using the Delta Exchange API for trading and would like to understand how to place bracket orders via API. Specifically, I want to:

  • Place a buy order when the price reaches a certain level (a stop entry order).
  • Set a stop-loss below the entry price.
  • Set a target above the entry price.

For example, if the current market price is 100, I want to:

  • Place a buy order at 105 (when the price reaches 105).
  • Set a stop-loss at 103.
  • Set a target at 109.

Could you please guide me on how to structure the API request for this? If possible, I would really appreciate an example request body to understand the parameters better.

Thank you for your help!

Bracket order: Delta Exchange Api

Stop order:
https://docs.delta.exchange/#place-order
https://docs.delta.exchange/#tocScreateorderrequest

you can give buy order with order type = stop loss limit, trigger = 100, limit = 105 to make an entry; or stop loss market with trigger =100 side = buy.

So I have to place two seperate orders, right? One stop loss limit order and a bracket order just for setting stop loss and profit.

yes and note that a bracket orders is applied on an existing position and always on the entire size of the position.

I couldn’t place a bracket order on a pending order? Only after the position filled I can place the bracket order, right?

Hi Midhun, Pls share code , will suggest changed

yes it applies only on a position and not on open orders

Hi @midhun , let me know if you’re query is resolved.

hey quick question so if i place a limit order with bracket and want to edit the bracket order i need to use the order id of the parent order ?

Yes, when you want to edit a bracket order (the stop loss or take profit parameters) that is attached to a limit order, you need to use the order ID of the parent order (the main limit order).

the problem here is after bracket order is placed and when i try to edit the order
{‘error’: {‘code’: ‘open_order_not_found’}, ‘success’: False} this is what comes . in delta webpage also these orders are under stop order rather than on open orders.

The error open_order_not_found means that the order with the given Id is no longer open and either it is filled or cancelled so you can’t edit it.
If it is filled, then bracket orders are created with their own Ids and they can be edited separately using those Ids.

can you give me the python codes to find those ids

@johngeorge The orders should be shown into your active orders section until the position is closed or one of the bracket orders get executed.
Their states wil be be pending if they are not triggered and open if they are triggered but not executed. Their stop_order_type will be either stop_loss_order or take_profit_order.
Get Active Orders API: Delta Exchange Api

Please find the python code for the same below.

import time
import requests
import hmac
import hashlib

API_BASE_URL = "https://api.india.delta.exchange"
API_KEY = ""
API_SECRET = ""

def generate_signature(secret, message):
    message = bytes(message, 'utf-8')
    secret = bytes(secret, 'utf-8')
    hash = hmac.new(secret, message, hashlib.sha256)
    return hash.hexdigest()

def print_active_orders():
    path = "/v2/orders"
    url = API_BASE_URL + path
    timestamp = str(int(time.time()))
    method = "GET"

    signature_data = method + timestamp + path
    signature = generate_signature(API_SECRET, signature_data)

    headers = {
        "api-key": API_KEY,
        "timestamp": timestamp,
        "signature": signature,
        "Content-Type": "application/json"
    }

    orders_response = requests.get(url, headers=headers)
    if orders_response.status_code == 200:
        print(f"Active orders: {orders_response.json()}")
    else:
        print(f"Error fetching orders: {orders_response.status_code} - {orders_response.text}")


if __name__ == "__main__":
    print_active_orders()
1 Like