# Getting wrong Historical data using API

**URL:** <https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767>\
**Category:** APIs & Algo Trading\
**Created:** [January 30, 2025, 5:54pm UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767 "2025-01-30T17:54:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prashant\_Panchal](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.delta.exchange/prashant_panchal/32/130_2.png) [@Prashant\_Panchal](https://community.delta.exchange/u/Prashant_Panchal)\
**Post date:** [January 30, 2025, 5:54pm UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767/1 "2025-01-30T17:54:22Z")

</div>

I am trying to fetch 1 min data from Delta Exchange India, which is getting wrong because It is not matching with the actual price on chart.

This data I am getting ::  
close high low open time volume  
0 105772.0 105795.5 105746.5 105767.0 2025-01-30 16:40:00 3334  
1 105767.0 105791.5 105671.5 105671.5 2025-01-30 16:39:00 3179  
2 105671.5 105691.5 105657.0 105682.5 2025-01-30 16:38:00 2932  
3 105697.5 105743.5 105686.5 105701.0 2025-01-30 16:37:00 5550  
4 105700.5 105796.0 105700.5 105728.5 2025-01-30 16:36:00 5400  
5 105728.5 105774.0 105641.5 105774.0 2025-01-30 16:35:00 11435  
6 105773.5 105776.0 105703.5 105766.0 2025-01-30 16:34:00 7794  
7 105769.0 105857.5 105767.5 105834.5 2025-01-30 16:33:00 4746  
8 105834.5 105942.0 105806.5 105929.5 2025-01-30 16:32:00 5049  
9 105929.5 105930.0 105867.5 105871.0 2025-01-30 16:31:00 4309

Code ::

date\_string\_start = “2025-01-30 12:00:00”  
date\_string\_end = “2025-01-30 22:10:00”  
pattern = “%Y-%m-%d %H:%M:%S”  
epoch\_time\_start = int(time.mktime(time.strptime(date\_string\_start, pattern)))  
epoch\_time\_end = int(time.mktime(time.strptime(date\_string\_end, pattern)))  
params = {  
‘resolution’: “1m”,  
‘symbol’: “BTCUSD”,  
‘start’: f"{epoch\_time\_start}“,  
‘end’: f”{epoch\_time\_end}"  
}  
response = requests.get(“[https://cdn.india.deltaex.org/v2/history/candles](https://cdn.india.deltaex.org/v2/history/candles)”, params=params)  
historical\_data = response.json()  
historical\_df = pd.DataFrame(historical\_data[‘result’])  
historical\_df[‘time’] = pd.to\_datetime(historical\_df[‘time’], unit=‘s’)  
print(historical\_df)

Can any one explain what is going wrong here ?

---

<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:** [January 31, 2025, 12:15am UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767/2 "2025-01-31T00:15:51Z")

</div>

call the endpoint ```  
r = requests.get(‘[https://api.india.delta.exchange/v2/history/candles](https://api.india.delta.exchange/v2/history/candles)’

```auto

```

---

<div class="post-metadata">

**Author:** ![Prashant\_Panchal](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.delta.exchange/prashant_panchal/32/130_2.png) [@Prashant\_Panchal](https://community.delta.exchange/u/Prashant_Panchal)\
**Post date:** [February 6, 2025, 3:10pm UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767/3 "2025-02-06T15:10:00Z")

</div>

Still getting same issue,  
@ayush.aggrwl @pankajbalani

---

<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 6, 2025, 5:58pm UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767/4 "2025-02-06T17:58:56Z")

</div>

Hi @Prashant_Panchal , the reason why even after using the correct endpointed as suggested above, you are getting a discrepancy in the api output and the charts on delta exchange website is because the api is outputing time in UTC and delta charts (on default) show time in IST (UTC+5.30).

pls add 5:30 ( + 19800 ) in epoch time to resolve this . here is a working code . I have saved the output in csv for your ease of verification of 1 min data.

```auto
import requests
import time
import pandas as pd

epoch_time_start = int(time.mktime(time.strptime("2025-01-30 12:00:00", "%Y-%m-%d %H:%M:%S"))) + 19800
epoch_time_end = int(time.mktime(time.strptime("2025-01-30 22:10:00", "%Y-%m-%d %H:%M:%S"))) + 19800

params = {
    "resolution": "1m",
    "symbol": "BTCUSD",
    "start": epoch_time_start,
    "end": epoch_time_end
}

response = requests.get("https://api.india.delta.exchange/v2/history/candles", params=params)
data = response.json()

if "result" in data:
    df = pd.DataFrame(data["result"])
    df["time"] = pd.to_datetime(df["time"], unit="s") + pd.Timedelta(hours=5, minutes=30)
    df.to_csv("historical_data.csv", index=False)
    print(df)
else:
    print("Error: 'result' key not found in response.")

```

---

<div class="post-metadata">

**Author:** ![8891703567](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.delta.exchange/8891703567/32/140_2.png) [@8891703567](https://community.delta.exchange/u/8891703567)\
**Post date:** [February 18, 2025, 5:06pm UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767/5 "2025-02-18T17:06:35Z")

</div>

I’m getting wrong prices when fetching BTCUSD using api for OHLC:  
{  
“result”: [  
{  
“close”: 52226.5,  
“high”: 52432.5,  
“low”: 52224,  
“open”: 52420.5,  
“time”: 1708298700,  
“volume”: 3621  
},  
{  
“close”: 52410.5,  
“high”: 52431,  
“low”: 52395,  
“open”: 52431,  
“time”: 1708298400,  
“volume”: 1406  
},  
{  
“close”: 52428.5,  
“high”: 52428.5,  
“low”: 52278.5,  
“open”: 52349.5,  
“time”: 1708298100,  
“volume”: 1592  
},  
{  
“close”: 52351.5,  
“high”: 52360.5,  
“low”: 52340.5,  
“open”: 52356.5,  
“time”: 1708297800,  
“volume”: 1495  
},  
{  
“close”: 52353.5,  
“high”: 52364,  
“low”: 52318.5,  
“open”: 52318.5,  
“time”: 1708297500,  
“volume”: 1325  
},  
{  
“close”: 52299.5,  
“high”: 52309.5,  
“low”: 52266,  
“open”: 52308,  
“time”: 1708297200,  
“volume”: 2648  
}  
],  
“success”: true  
}  
However the price is about 1 lakh.

---

<div class="post-metadata">

**Author:** ![8891703567](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.delta.exchange/8891703567/32/140_2.png) [@8891703567](https://community.delta.exchange/u/8891703567)\
**Post date:** [February 20, 2025, 1:54am UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767/6 "2025-02-20T01:54:32Z")

</div>

![crypto](https://canada1.discourse-cdn.com/flex004/uploads/deltaexchange/original/1X/b72088b1caa0892dfdac141725b06ff7b9789a46.png)  
when fetching historical data, the price is about 51577, whereas actual market price was 98900~. Anyone facing the issue when fetching OHLC.

---

<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:38am UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767/7 "2025-02-24T08:38:49Z")

</div>

Hi @8891703567 , you are passing start and end time for Sun Feb 18 2024 10:17:15 GMT+0530 (India Standard Time). pls pass current time to get updated prices. also use the correct endpoint. ```  
[https://api.india.delta.exchange/v2/history/candles](https://api.india.delta.exchange/v2/history/candles)

```auto

```

---

<div class="post-metadata">

**Author:** ![praveenadelta](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@praveenadelta](https://community.delta.exchange/u/praveenadelta)\
**Post date:** [July 8, 2025, 12:04pm UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767/8 "2025-07-08T12:04:17Z")

</div>

> [@ayush.aggrwl](#):
>
> u are passing start and end time for Sun Feb 18 2024 10:17:15 GMT+0530 (India Standard Time). pls pass current time to get updated prices. also use the correct endpoint. ```

seems options history data is not coming properly .. BTCUSD history  
is coming fine

---

<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:** [July 8, 2025, 12:20pm UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767/9 "2025-07-08T12:20:29Z")

</div>

> [@praveenadelta](#):
>
> seems options history data is not coming properly .. BTCUSD history  
> is coming fine

Hi @praveenadelta , can you share which contract you are trying to fetch historical OHLC data for, For me the data is coming correct for BTC and ETH options.

---

<div class="post-metadata">

**Author:** ![praveenadelta](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@praveenadelta](https://community.delta.exchange/u/praveenadelta)\
**Post date:** [July 8, 2025, 3:11pm UTC](https://community.delta.exchange/t/getting-wrong-historical-data-using-api/767/10 "2025-07-08T15:11:47Z")

</div>

🙂 quote=“praveenadelta, post:8, topic:767”]  
.. BTCUSD history  
is coming fine  
[/quote]

thanks Ayush for the response. it was my bad there was a typo in contract name. it is fine ..🙂
