the code is working fine in replit.com and jupyter notebook but doesn't work on my local env.
I don't understand why. it either say : name 'elem' is not defined (line 61) or Empty DataFrame Columns: [price] Index: [].
the code :
...
url = "https://www.bitmex.com/api/v1/trade"
filters = {
'startTime': td
}
params = {
'symbol': '.BVOL24H',
'filter': json.dumps(filters),
}
response = requests.get(url, params=params)
bvol24_list = []
for elem in response.json():
elem['timestamp'] = pd.to_datetime(elem['timestamp'], format="%Y-%m-%d %H:%M")
mins = elem['timestamp'].strftime("%Y-%m-%d %H:%M")
bvol24_list.append([elem['price'], mins])
vol_df = pd.DataFrame(data=bvol24_list, columns=['price', 'timestamp'])
vol_df = vol_df.set_index('timestamp')
print(elem['symbol'])
print(vol_df)
it does work fine on jupyter notebook:
.BVOL24H
price
timestamp
2021-12-27 17:15 1.97
2021-12-27 17:20 1.97
...
2021-12-27 18:10 1.99
Edit : it didn't work because of the different timezone and the delta applied on it, the list was empty because it couldn't get the data so the local variable was referenced "before assignment".
response.json()is an empty list