I used the code below to download the data, but upon verification, there is a significant discrepancy when compared to iChart. Minor differences would be understandable, but the gap is substantial. Is there a way to double-check if this is the actual data or if there might be an error?
from Dhan_Tradehull import Tradehull
import datetime
import os
client_id = "XXXXXXXXXX"
access_token = "eyJ0eXAiOiJ...."
tsl = Tradehull(client_id, access_token)
watchlist = ["NIFTY", "BANKNIFTY", "TCS", "INFY", "RELIANCE"]
expiries = ["2024-01-25", "2024-02-29", "2024-03-28"]
for name in watchlist:
for expiry in expiries:
try:
from_date = (
datetime.datetime.strptime(expiry, "%Y-%m-%d")
- datetime.timedelta(days=30)
).strftime("%Y-%m-%d")
data = tsl.get_expired_option_data(
tradingsymbol=name,
exchange="NSE",
interval=1,
expiry_flag="MONTH",
expiry_code=1,
strike="ATM",
option_type="CALL",
from_date=from_date,
to_date=expiry
)
path = f"Options data/{name}/ATM"
os.makedirs(path, exist_ok=True)
file_name = f"{name}_{expiry}.csv"
data.to_csv(f"{path}/{file_name}", index=False)
print(f"{name} {expiry} : Download completed")
except Exception as e:
print(f"{name} {expiry} : Error {e}")
continue
BN Example



