Hi, I am new to Dhan Api and using gemini to build a code to fetch nifty 50 LTP and 20 market depth data for nifty 50 stocks. I am stuck in fetching nifty 50 data.
Tried the below code i found in this forum, as a proxy to LTP, but getting error
!pip install dhanhq
from dhanhq import dhanhq
from datetime import datetime, timedelta
client_id =
access_token =
dhan = dhanhq(client_id,access_token)
BN=dhan.historical_daily_data(
symbol='BANKNIFTY',
exchange_segment='IDX_I',
instrument_type='INDEX',
expiry_code=0,
from_date='2024-09-01',
to_date='2024-09-18'
)
# This is optional , just to convert time stamps properly
data= pd.DataFrame(BN['data'])
data['start_Time'] = data['start_Time'].astype(int)
data['start_Time'] = data['start_Time'].apply(dhan.convert_to_date_time)
data