# Create Order Fail

**URL:** <https://community.delta.exchange/t/create-order-fail/868>\
**Category:** APIs & Algo Trading\
**Created:** [March 5, 2025, 8:50pm UTC](https://community.delta.exchange/t/create-order-fail/868 "2025-03-05T20:50:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arbaz00789](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@arbaz00789](https://community.delta.exchange/u/arbaz00789)\
**Post date:** [March 5, 2025, 8:50pm UTC](https://community.delta.exchange/t/create-order-fail/868/1 "2025-03-05T20:50:39Z")

</div>

Am using **from delta\_rest\_client import DeltaRestClient** to place order this is my actual code.

```auto
from delta_rest_client import DeltaRestClient

def place_order():
    response = delta_client.place_order(
        product_id=27,
        size=0.1,
        side='buy'
  )

```

Getting below Error:

```auto
HTTPError: 401 HTTP Error: Unauthorized {"error":{"code":"expired_signature","context":{"request_time":1741207371,"server_time":1741206574}},"success":false} for url: https://api.india.delta.exchange/v2/orders

```

Then i tried working with http request below code.

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

```

```auto
def place_order():
    base_url = 'https://api.india.delta.exchange'
    api_key = ''
    api_secret = ''
    
    method = 'POST'
    timestamp = str(int(time.time()))
    path = '/v2/orders'
    url = f'{base_url}{path}'
    order_payload = {
        "order_type":"limit_order",
        "size":0.1,
        "side":"buy",
        "limit_price":0.005,
        "product_id":27
    }
        
    payload = json.dumps(order_payload)
    print(payload)
    signature_data = method + timestamp + path + payload
    signature = generate_signatureNew(api_secret, signature_data)
    
    req_headers = {
      'api-key': api_key,
      'timestamp': timestamp,
      'signature': signature,
      'User-Agent': 'rest-client',
      'Content-Type': 'application/json'
    }
    
    response = requests.request(method, url, data=payload, params={}, timeout=(3, 27), headers=req_headers)
    print(response.json())

```

Getting below Error:

```auto
{'error': {'code': 'expired_signature', 'context': {'request_time': 1741208402, 'server_time': 1741207605}}, 'success': False}

```

---

<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 6, 2025, 3:37am UTC](https://community.delta.exchange/t/create-order-fail/868/2 "2025-03-06T03:37:09Z")

</div>

Hi @arbaz00789 , Your request is failing with a 401 Unauthorized error due to an expired signature.

The server time (1741206574) and your request time (1741207371) are not in sync, which is causing authentication to fail. Please sync your system clock with an NTP server (Network Time Protocol) to ensure accurate timestamps. You can manually sync Date & Time from the settings in your system. Once your clock is synced, try placing the request again. Let me know if the issue persists!

---

<div class="post-metadata">

**Author:** ![arbaz00789](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@arbaz00789](https://community.delta.exchange/u/arbaz00789)\
**Post date:** [March 6, 2025, 9:23pm UTC](https://community.delta.exchange/t/create-order-fail/868/3 "2025-03-06T21:23:40Z")

</div>

Thanks this is working now.

Is there any way that i check check my **BTCUSD** order is place and i can delete those orders and punch a new order.

I need to perform following steps

1. First i need to check if any btcusd order is placed.
2. Than get the order details from delta
3. Than delete this order with these keys : order\_id, product\_id
4. Than place new order.

Is there any simpler way to delete current position only with **BTCUSD** order and create new 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:** [March 7, 2025, 8:02am UTC](https://community.delta.exchange/t/create-order-fail/868/4 "2025-03-07T08:02:05Z")

</div>

Hi @arbaz00789 , pls go through [Delta Exchange Api](https://docs.delta.exchange/#delta-exchange-api-v2-orders).

you can follow a 3 step approach

```auto
# fetch open orders and check any btc order is placed or no
open_orders = delta_client.request("GET", "/v2/orders", auth=True)
btc_orders = [order for order in open_orders["result"] if order["product_symbol"] == "BTCUSD"]

# Cancel Existing BTCUSD Orders
for order in btc_orders:
    delta_client.cancel_order(order["product_id"], order["id"])
    print(f"Canceled Order ID: {order['id']}")

#Place a new btc order
new_order = delta_client.place_order(
    product_id=27,  
    size=1, 
    side="buy", 
    order_type=OrderType.LIMIT,
    limit_price="97000"
)
print("New BTCUSD order placed:", new_order)

```

customise the above code as per your overall code. let me know if you have any other queries
