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”, 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 ?
Still getting same issue,
@ayush.aggrwl @pankajbalani
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.
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.")
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.
when fetching historical data, the price is about 51577, whereas actual market price was 98900~. Anyone facing the issue when fetching OHLC.
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