I'm trying to make a crypto trading bot in python, and i collect historical data (prices and stuff) with the library called ccxt, and store it in pandas dataframe. When i try to store more than 999 rows, i get the error shown below (KeyError: 999). Basically it won't let me store more than 999 rows. Is there any way to get more then 999 data in pandas dataframe?
The code is pretty large, but here are some snippets:
Data frame build:
exchange = ccxt.binance()
bars = exchange.fetch_ohlcv(pair_to_trade, timeframe=timeframe, limit=amount_of_timeframe)
df = pd.DataFrame(bars[:-1], columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
Last_row_index:
for i in range(1, amount_of_timeframe-1): # where amount_of_timeframe > 1000
last_row_index = i
previous_row_index = last_row_index - 1
Data frame looks like this:
timestamp open high ... upperband lowerband in_uptrend
0 2021-09-05 16:27:00 3913.51 3914.97 ... NaN NaN True
1 2021-09-05 16:28:00 3914.04 3914.22 ... NaN NaN True
2 2021-09-05 16:29:00 3910.01 3912.00 ... NaN NaN True
3 2021-09-05 16:30:00 3911.84 3911.85 ... NaN NaN True
...
995 2021-09-06 09:02:00 3956.10 3956.36 ... 3967.517857 3942.412143 False
996 2021-09-06 09:03:00 3954.32 3954.32 ... 3964.035000 3941.775000 False
997 2021-09-06 09:04:00 3951.52 3955.85 ... 3964.035000 3941.610714 False
998 2021-09-06 09:05:00 3955.58 3955.58 ... 3964.035000 3943.252857 False
Error:
File "D:/myfolders/supertrendStrategy/main.py", line 105, in testStrategy
if not stdf['in_uptrend'][previous_row_index] and stdf['in_uptrend'][last_row_index]:
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py", line 882, in __getitem__
return self._get_value(key)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py", line 989, in _get_value
loc = self.index.get_loc(label)
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\range.py", line 357, in get_loc
raise KeyError(key) from err
KeyError: 999
ccxt.binance()
won't let you fetch more than 1000 candles. Try another API, that works with bigger data