Handle out of process token refreshes
parent
a4fe86719f
commit
ff437ce9e1
|
@ -60,9 +60,10 @@ class Client:
|
||||||
self._conf = config
|
self._conf = config
|
||||||
self.access_data = {}
|
self.access_data = {}
|
||||||
self.user_data = {}
|
self.user_data = {}
|
||||||
self._apply_config(config)
|
self._reload_config(config)
|
||||||
|
|
||||||
def _apply_config(self, config):
|
def _reload_config(self, config=None):
|
||||||
|
self._conf = config or get_config()
|
||||||
self.access_data = dict(self._conf['questrade'])
|
self.access_data = dict(self._conf['questrade'])
|
||||||
|
|
||||||
async def _new_auth_token(self) -> dict:
|
async def _new_auth_token(self) -> dict:
|
||||||
|
@ -130,8 +131,7 @@ class Client:
|
||||||
raise QuestradeError("API is down for maintenance")
|
raise QuestradeError("API is down for maintenance")
|
||||||
elif qterr.args[0].decode() == 'Bad Request':
|
elif qterr.args[0].decode() == 'Bad Request':
|
||||||
# likely config ``refresh_token`` is expired
|
# likely config ``refresh_token`` is expired
|
||||||
_token_from_user(self._conf)
|
self._reload_config()
|
||||||
self._apply_config(self._conf)
|
|
||||||
data = await self._new_auth_token()
|
data = await self._new_auth_token()
|
||||||
else:
|
else:
|
||||||
raise qterr
|
raise qterr
|
||||||
|
@ -313,7 +313,14 @@ async def poll_tickers(
|
||||||
_cache = {}
|
_cache = {}
|
||||||
|
|
||||||
while True: # use an event here to trigger exit?
|
while True: # use an event here to trigger exit?
|
||||||
quotes_resp = await client.api.quotes(ids=ids)
|
try:
|
||||||
|
quotes_resp = await client.api.quotes(ids=ids)
|
||||||
|
except QuestradeError as qterr:
|
||||||
|
if "Access token is invalid" in str(qterr.args[0]):
|
||||||
|
# out-of-process piker may have renewed already
|
||||||
|
client._reload_config()
|
||||||
|
quotes_resp = await client.api.quotes(ids=ids)
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
quotes = quotes_resp['quotes']
|
quotes = quotes_resp['quotes']
|
||||||
# log.trace(quotes)
|
# log.trace(quotes)
|
||||||
|
|
Loading…
Reference in New Issue