tedchou12 / webull

Unofficial APIs for Webull.
MIT License
601 stars 185 forks source link

received error rzone on api login #419

Closed hadenponish1 closed 1 year ago

hadenponish1 commented 1 year ago

New issue logging into retrieve orders. Code is below, previously was able to pull no problem


from dotenv import load_dotenv
import os

# Load environment variables from .env file
load_dotenv()
webull_email = os.environ['webull_email']
webull_pass = os.environ['webull_pass']
webull_access_token = os.environ['access_token']
webull_uuid = os.environ['webull_uuid']

wb = webull()

creds = wb.login(webull_email, webull_pass)
wb.api_login(access_token= webull_access_token, uuid = webull_uuid)
orders = wb.get_history_orders(status = 'All', count = 10000)
print(len(orders))```

error is 

--------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[62], line 18
     15 wb = webull()
     17 creds = wb.login(webull_email, webull_pass)
---> 18 wb.api_login(access_token= webull_access_token, uuid = webull_uuid)
     19 orders = wb.get_history_orders(status = 'All', count = 10000)
     20 print(len(orders))

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/webull/webull.py:271, in webull.api_login(self, access_token, refresh_token, token_expire, uuid, mfa)
    269 self._token_expire = token_expire
    270 self._uuid = uuid
--> 271 self._account_id = self.get_account_id()

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/webull/webull.py:325, in webull.get_account_id(self, id)
    323 result = response.json()
    324 if result['success'] and len(result['data']) > 0 :
--> 325     self.zone_var = str(result['data'][int(id)]['rzone'])
    326     self._account_id = str(result['data'][int(id)]['secAccountId'])
    327     return self._account_id

KeyError: 'rzone'
hadenponish1 commented 1 year ago

resolved. Another issue due to changing access_token, my variable was using an outdated one. For those that may encounter this issue you can use steps below to adjust.

##if there's an rzone key error or some issue logging in it's likely due to an updated access_token or did. To correct:
##1. open incognito browser, log-in to the webull account with network tab open 
##2. open the v2 request and find the data needed, access token will be in one of the json requests, look in the headers. 
##3. swap out the access_token in the .env file 

after doing this, I was able to successfully log-in and retrieve all orders as expected.