I'm getting an error while trying to get the chart data

Code:
import pdb

import talib

from Dhan_Tradehull import Tradehull

import pandas as pd

client_code = “xxxxxxxxx”

token_id = “xxxxxxxxxx”

tsl = Tradehull(client_code, token_id)

watchlist = [

"JSWSTEEL",

"TATACONSUM",

"HINDALCO",

"M&M",

"HCLTECH",

"TATASTEEL",

"WIPRO",

"BEL",

"TCS",

"BHARTIARTL",

"HDFCLIFE",

"SHRIRAMFIN",

"EICHERMOT",

"TECHM",

"ONGC",

"SUNPHARMA",

"MAXHEALTH",

"BAJAJ-AUTO",

"LT",

"TMPV",

"GRASIM",

"APOLLOHOSP",

"ADANIPORTS",

"TRENT",

"NESTLEIND",

"JIOFIN",

"BAJAJFINSV",

"SBIN",

"AXISBANK",

"KOTAKBANK",

"DRREDDY",

"NTPC",

"ETERNAL",

"HDFCBANK",

"COALINDIA",

"ADANIENT",

"ULTRACEMCO",

"ITC",

"ASIANPAINT",

"SBILIFE",

"MARUTI",

"RELIANCE",

"CIPLA",

"ICICIBANK",

"HINDUNILVR",

"BAJFINANCE",

"TITAN",

"INFY",

"POWERGRID",

"INDIGO",

]

for stock_name in watchlist:

chart = tsl.get_intraday_data(stock_name, "NSE", 1)

print(chart)

Error:
File “c:\Users\imran\OneDrive\Desktop\1st Algo\First Algo\Dhan_Tradehull.py”, line 253, in get_intraday_data
ohlc = self.Dhan.intraday_minute_data(str(security_id),exchangeSegment,instrument_type)
TypeError: dhanhq.intraday_minute_data() missing 2 required positional arguments: ‘from_date’ and ‘to_date’

Hi @IMRAN_BAIG ,

tsl.get_intraday_data was a old method to get historical data.. it gives data only for today, which makes problem if we want to create indicators on it.

Dhanhq was upgraded and now we can use get_historical_data which gives data for last 5 working days.

Retrieve historical or intraday data:

Get Historical Data

  • tsl.get_historical_data(tradingsymbol: str, exchange: str, timeframe: str, debug: str = “NO”)
    • Arguments:
      • tradingsymbol (str): The trading symbol for the instrument you want to fetch data for (e.g., ‘NIFTY’, ‘ACC’).
      • exchange (str): The exchange where the instrument is traded (e.g., ‘NSE’, ‘INDEX’).
      • timeframe (str): The timeframe for the data. It can be:
        • ‘1’ for 1-minute candles
        • ‘5’ for 5-minute candles
        • ‘15’ for 15-minute candles
        • ‘25’ for 25-minute candles
        • ‘60’ for 60-minute candles
        • ‘DAY’ for daily candles
      • debug (optional, str): Set to “YES” to enable detailed API response logging. Default is “NO”.
    • Sample Code:

data = tsl.get_historical_data(tradingsymbol='NIFTY', exchange='INDEX', timeframe="DAY") 
data = tsl.get_historical_data(tradingsymbol='ACC', exchange='NSE', timeframe="1")

Guide to use the updated codebase:
Refer the below pypi link for more details:

Video reference :

1 Like