# Not Getting Active orders

**URL:** <https://community.delta.exchange/t/not-getting-active-orders/714>\
**Category:** APIs & Algo Trading\
**Created:** [January 12, 2025, 4:33pm UTC](https://community.delta.exchange/t/not-getting-active-orders/714 "2025-01-12T16:33:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepakc8052](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Deepakc8052](https://community.delta.exchange/u/Deepakc8052)\
**Post date:** [January 12, 2025, 4:33pm UTC](https://community.delta.exchange/t/not-getting-active-orders/714/1 "2025-01-12T16:33:27Z")

</div>

import time  
import hmac  
import hashlib  
import requests  
import json

# Set your API key and secret

‘’'# API endpoint for cancelling orders  
base\_url = “[https://cdn.india.deltaex.org/v2/orders](https://cdn.india.deltaex.org/v2/orders)”

# Function to generate the signature

def generate\_signature(api\_key, api\_secret, params):  
query\_string = ‘&’.join([f"{key}={value}" for key, value in sorted(params.items())])  
return hmac.new(api\_secret.encode(), query\_string.encode(), hashlib.sha256).hexdigest()

‘’’

# Your Delta Exchange API credentials

API\_KEY = api\_key  
API\_SECRET = api\_secret

# Base URL for Delta Exchange API

BASE\_URL = “[https://api.india.delta.exchange](https://api.india.delta.exchange)”

# Function to create the signature

def create\_signature(endpoint, params):  
params[‘api\_key’] = API\_KEY  
params[‘timestamp’] = str(int(time.time() \* 1000))  
query\_string = ‘&’.join([f"{key}={value}" for key, value in sorted(params.items())])  
signature = hmac.new(API\_SECRET.encode(‘utf-8’), query\_string.encode(‘utf-8’), hashlib.sha256).hexdigest()  
return signature

def generate\_signature(method, endpoint, payload, api\_secret):  
timestamp = str(int(time.time()))  
signature\_data = method + timestamp + endpoint + payload  
message = bytes(signature\_data, ‘utf-8’)  
secret = bytes(api\_secret, ‘utf-8’)  
hash = hmac.new(secret, message, hashlib.sha256)  
return hash.hexdigest(), timestamp

def get\_active\_orders(api\_key, secret\_key):  
# Generate the current timestamp in Unix time (seconds)  
timestamp = str(int(time.time()))

```
# Define the endpoint and method
method = 'GET'
endpoint = '/v2/orders'

# Parameters for the GET request (to fetch active orders)
params = {
    'status': 'ACTIVE', # Fetching only active orders
}

# The string to be signed should include: method + timestamp + endpoint
signature_data = f"{method}{timestamp}{endpoint}"

# Generate the signature using HMAC with SHA256
signature = hmac.new(secret_key.encode(), signature_data.encode(), hashlib.sha256).hexdigest()

# Define the URL for the wallet balances endpoint
url = f'https://api.india.delta.exchange{endpoint}'

# Set the headers for the request
headers = {
    'Accept': 'application/json',
    'api-key': api_key,
    'signature': signature,
    'timestamp': timestamp
}

# Send the GET request to the API
response = requests.get(url, headers=headers)

# Check if the response status code is 200 (OK)
if response.status_code == 200:
    # If successful, print the JSON response
    data = response.json()

    print(data)

```

# Function to get active orders

def get\_active\_orders\_1():  
endpoint = ‘/v2/orders’  
params = {  
‘status’: ‘ACTIVE’, # Fetching only active orders  
}

```
# Create signature for the request
params['signature'] = create_signature(endpoint, params)

# Construct full URL
url = BASE_URL + endpoint

# Send GET request to fetch active orders
response = requests.get(url, params=params)

if response.status_code == 200:
    return response.json() # Return the active orders in JSON format
else:
    print(f"Error: {response.status_code}, {response.text}")
    return None

```

# Fetch and print active orders

active\_orders = get\_active\_orders(api\_key,api\_secret)  
if active\_orders:  
print(active\_orders)

getting below response:  
{‘meta’: {‘after’: None, ‘before’: None, ‘limit’: 10, ‘total\_count’: 0}, ‘result’: , ‘success’: True}

but an active order was already there..  
pls help me in this code, if I’m approaching in right way.

---

<div class="post-metadata">

**Author:** ![shubhamjdelta](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@shubhamjdelta](https://community.delta.exchange/u/shubhamjdelta)\
**Post date:** [January 13, 2025, 6:25am UTC](https://community.delta.exchange/t/not-getting-active-orders/714/2 "2025-01-13T06:25:45Z")

</div>

[https://docs.delta.exchange/#get-active-orders](https://docs.delta.exchange/#get-active-orders)

This is documentation for getting open orders endpoint.  
In the below table for parameters:  
‘states’ (not ‘status’) param can have values like - open,pending.  
Currently you have sending params = {‘status’: ‘ACTIVE’}.  
You can send {‘states’: ‘open’}
