'AttributeError: 'str' object has no attribute '_historical_klines'

I am brand new to coding bots and coding in general. I copied a simple bot tutorial for beginners. The follwing part is for getting historical data of crypto stocks:

def gethourlydata(symbol):
    frame = pd.DataFrame(Client.get_historical_klines(symbol,
                                                      '1hr',
                                                      'now UTC',
                                                      '25 hours ago UTC'))
    frame = frame.iloc[:,:5]
    frame.columns = ['Time','Open','High','Low','Close']
    frame[['Open','High','Low','Close']] = frame[['Open','High','Low','Close']].astype(float)
    frame.Time = pd.to_datetime(frame.Time, unit='ms')
    return frame

First I had to put in a start_str because it was supposedly missing. I did so,executed the function for 'BTCUSDT', and got this:

    AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_1473/2916929938.py in <module>
----> 1 df = gethourlydata('BTCUSDT')

/tmp/ipykernel_1473/2893431243.py in gethourlydata(symbol)
      3                                                       '1hr',
      4                                                       'now UTC',
----> 5                                                       '25 hours ago UTC'))
      6     frame = frame.iloc[:,:5]
      7     frame.columns = ['Time','Open','High','Low','Close']

~/.local/lib/python3.7/site-packages/binance/client.py in get_historical_klines(self, symbol, interval, start_str, end_str, limit, klines_type)
    930 
    931         """
--> 932         return self._historical_klines(symbol, interval, start_str, end_str=end_str, limit=limit, klines_type=klines_type)
    933 
    934     def _historical_klines(self, symbol, interval, start_str, end_str=None, limit=500,

AttributeError: 'str' object has no attribute '_historical_klines'

I have tried many different methods, e.g. defining 'self','klines_type',etc. in detail, and still some error appears. All I'm to do is prove to myself that I can at least run a bot for on my jupyter notebook.

Could someone please help or at least give so tips?

Thank you!



Solution 1:[1]

You firstly have to initialize client

try this -

from binance.client import Client
my_client = Client("","") # for this operation you dont need to use keys
my_client.get_historical_klines((symbol,'1hr','now UTC','25 hours ago UTC'))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1