Unable to fetch historical data

Hi, i am trying to make a bot using super trend and EMA, for that i need historical data to calculate indicators and live data to generate signals. But it gives me historical data till 5 Jan only. And i am unable to find any way in API to get live price of all coins except BTC, ETH, SOL. Please help me with that. I am sharing the code below it gives me response 500 when i try to get historical data.
headers = {
‘Accept’: ‘application/json’
}

r = requests.get('https://api.india.delta.exchange/v2/history/candles', params={
    'resolution': '5m', 'symbol': 'BTCUSD', 'start': start_time_unix, 'end': end_time_unix
}, headers=headers)
data = r.json().get("result", [])

The Candles API provides up to 4000 candles per request. At a resolution of 5 minutes, there are 288 candles in a day (24 * 60 / 5), allowing data retrieval for approximately 14 days (4000 / 288).
For a longer time span, consider using higher resolutions like 30m, 1h, or 1d.
For live contract prices, use the Tickers API. API Guide - Delta Exchange Api

Thank you for response. I am only trying to get Data for last 24 hours but there is no data available. I get response 500 from server. The last data available is till 5 jan only, after that it gives 500 response.

1 Like

Let us know what values you are passing for start and end. Attached screenshot for last 24 hrs candles code and output.

I was converting time into milliseconds but according to API it should be in seconds. here is the final code now.

from datetime import datetime,timedelta
import requests
import pandas as pd

DELTA_API_URL = “https://api.delta.exchange/v2

def fetch_ohlc(symbol=“BTCUSD”, interval=‘5m’, limit=300):
# Calculate interval in seconds
interval_in_seconds = 5 * 60 # For 5-minute interval

# Calculate start and end time for the last `limit` candles
end_time = datetime.now()
end_time_unix = int(end_time.timestamp())  # Convert to seconds
start_time_unix = end_time_unix - (limit * interval_in_seconds)  # Calculate start time

headers = {
    'Accept': 'application/json'
}

# Make the request
r = requests.get(
    'https://api.india.delta.exchange/v2/history/candles',
    params={
        'resolution': interval,
        'symbol': symbol,
        'start': start_time_unix,
        'end': end_time_unix
    },
    headers=headers
)

# Validate response
if r.status_code == 200:
    data = r.json().get("result", [])
    df = pd.DataFrame(data)
    print(df)
else:
    print(f"Error: {r.status_code}, {r.text}")

fetch_ohlc()