piker/piker
Tyler Goodlet 395f0c8e4a Synchronize Questrade token refreshing per client
Questrade's API is half baked and can't handle concurrency.
It allows multiple concurrent requests to most endpoints *except*
for the auth endpoint used to refresh tokens:

    https://www.questrade.com/api/documentation/security

I've gone through extensive dialogue with their API team and despite
making what I think are very good arguments for doing the request
serialization on the server side, they decided that I should instead
do the "locking" on the client side. Frankly it doesn't seem like they
have that competent an engineering department as it took me a long time
to explain the issue even though it's rather trivial and probably not
that hard to fix; maybe it's better this way.

This adds a few things to ensure more reliable token refreshes on
expiry:

- add a `@refresh_token_on_err` decorator which can be used on `_API`
  methods that should refresh tokens on failure
- decorate most endpoints with this *except* for the auth ep
- add locking logic for the troublesome scenario as follows:
  * every time a request is sent out set a "request in progress" event
    variable that can be used to determine when no requests are currently
    outstanding
  * every time the auth end point is hit in order to refresh tokens set
    an event that locks out other tasks from making requests
  * only allow hitting the auth endpoint when there are no "requests in
    progress" using the first event
  * mutex all auth endpoint requests; there can only be one outstanding

- don't hit the accounts endpoint at client startup; we want to
  eventually support keys from multiple accounts and you can disable
  account info per key and just share the market data function
2019-02-09 21:39:22 -05:00
..
brokers Synchronize Questrade token refreshing per client 2019-02-09 21:39:22 -05:00
testing Import client for now until we make a proper shim 2018-02-12 10:35:54 -05:00
ui Always set contract sub state 2019-01-14 21:13:22 -05:00
__init__.py Go GPLv3 2018-11-12 00:29:43 -05:00
_async_utils.py An explicit name is prolly better 2018-11-25 19:23:07 -05:00
calc.py Allow specifying number of displayed digits 2018-11-13 18:42:34 -05:00
cli.py Support pub-sub of monitor's symbol selection 2018-12-30 14:59:54 -05:00
log.py Don't add more then one stderr handler 2018-11-22 16:31:01 -05:00
watchlists.py Expose remove errors to caller 2018-04-10 14:12:06 -04:00