# How to Place Bracket Orders via API

**URL:** <https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821>\
**Category:** APIs & Algo Trading\
**Created:** [February 22, 2025, 8:16pm UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821 "2025-02-22T20:16:29Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![midhun](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@midhun](https://community.delta.exchange/u/midhun)\
**Post date:** [February 22, 2025, 8:16pm UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/1 "2025-02-22T20:16:29Z")

</div>

**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!

---

<div class="post-metadata">

**Author:** ![pankajbalani](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.delta.exchange/pankajbalani/32/29_2.png) [@pankajbalani](https://community.delta.exchange/u/pankajbalani)\
**Post date:** [February 23, 2025, 3:13am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/2 "2025-02-23T03:13:28Z")

</div>

Bracket order: [Delta Exchange Api](https://docs.delta.exchange/#place-bracket-order)

Stop order:  
[https://docs.delta.exchange/#place-order](https://docs.delta.exchange/#place-order)  
[https://docs.delta.exchange/#tocScreateorderrequest](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.

---

<div class="post-metadata">

**Author:** ![midhun](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@midhun](https://community.delta.exchange/u/midhun)\
**Post date:** [February 23, 2025, 7:15am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/5 "2025-02-23T07:15:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pankajbalani](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.delta.exchange/pankajbalani/32/29_2.png) [@pankajbalani](https://community.delta.exchange/u/pankajbalani)\
**Post date:** [February 23, 2025, 9:20am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/6 "2025-02-23T09:20:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![midhun](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@midhun](https://community.delta.exchange/u/midhun)\
**Post date:** [February 23, 2025, 9:28am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/9 "2025-02-23T09:28:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ayush.aggrwl](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@ayush.aggrwl](https://community.delta.exchange/u/ayush.aggrwl)\
**Post date:** [February 24, 2025, 8:36am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/10 "2025-02-24T08:36:04Z")

</div>

Hi Midhun, Pls share code , will suggest changed

---

<div class="post-metadata">

**Author:** ![pankajbalani](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.delta.exchange/pankajbalani/32/29_2.png) [@pankajbalani](https://community.delta.exchange/u/pankajbalani)\
**Post date:** [March 3, 2025, 4:02am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/11 "2025-03-03T04:02:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ayush.aggrwl](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@ayush.aggrwl](https://community.delta.exchange/u/ayush.aggrwl)\
**Post date:** [March 3, 2025, 7:52am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/12 "2025-03-03T07:52:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johngeorge](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.delta.exchange/johngeorge/32/165_2.png) [@johngeorge](https://community.delta.exchange/u/johngeorge)\
**Post date:** [June 13, 2025, 11:50am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/13 "2025-06-13T11:50:51Z")

</div>

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**?

---

<div class="post-metadata">

**Author:** ![ayush.aggrwl](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@ayush.aggrwl](https://community.delta.exchange/u/ayush.aggrwl)\
**Post date:** [June 14, 2025, 4:15am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/14 "2025-06-14T04:15:54Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![johngeorge](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.delta.exchange/johngeorge/32/165_2.png) [@johngeorge](https://community.delta.exchange/u/johngeorge)\
**Post date:** [June 14, 2025, 7:30pm UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/15 "2025-06-14T19:30:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ayush.aggrwl](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@ayush.aggrwl](https://community.delta.exchange/u/ayush.aggrwl)\
**Post date:** [June 16, 2025, 5:47am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/16 "2025-06-16T05:47:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![johngeorge](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.delta.exchange/johngeorge/32/165_2.png) [@johngeorge](https://community.delta.exchange/u/johngeorge)\
**Post date:** [June 16, 2025, 9:26am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/17 "2025-06-16T09:26:28Z")

</div>

> [@ayush.aggrwl](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![manku.pathak](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@manku.pathak](https://community.delta.exchange/u/manku.pathak)\
**Post date:** [June 17, 2025, 5:39am UTC](https://community.delta.exchange/t/how-to-place-bracket-orders-via-api/821/18 "2025-06-17T05:39:15Z")

</div>

@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](https://docs.delta.exchange/#get-active-orders)

Please find the python code for the same below.

```auto
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()

```
