0

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".

1
  • Probably because response.json() is an empty list Commented Dec 27, 2021 at 20:15

1 Answer 1

1

You could try to determine if "requests.get(url, params=params)" returns the expected values. Start by looking at the status_code of the response:

response.status_code

If the code is anything other than 200, there is likely a problem with the call itself.

If the code is 200, check to see what is actually contained in the response:

print(response.json())
Sign up to request clarification or add additional context in comments.

4 Comments

I did try that, the code is 200 but the list in empy. UnboundLocalError: local 'ele' referenced before assignement, I does work on any online IDE though.. I also tried to assign a global variable to 'ele' but it returns an error.
@Jordan what response is returned if you remove the filter and/or parameter?
@Jordan Also, do you see the quote information when you go to "bitmex.com/api/v1/trade" in your local browser?
I edited my post, the problem is solved, I tried removing the filters, it worked fine, I noticed I had a different timezone, that's why it was working on jupyter (online) and not on my local env.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.