Skip to content

Commit

Permalink
Merge pull request #24 from tarioch/bugfix/handle_ibkr_throttle
Browse files Browse the repository at this point in the history
deal with throttling from ibkr when fetching prices
  • Loading branch information
tarioch authored Jul 28, 2020
2 parents d75d59e + 5625971 commit 8b1004a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/tariochbctools/plugins/prices/ibkr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
from os import environ
from ibflex import client, parser
from datetime import datetime
from time import sleep


class Source(source.Source):
def get_latest_price(self, ticker):
token = environ['IBKR_TOKEN']
queryId = environ['IBKR_QUERY_ID']

response = client.download(token, queryId)
try:
response = client.download(token, queryId)
except client.ResponseCodeError as e:
if e.code == '1018':
sleep(10)
response = client.download(token, queryId)
else:
raise e

statement = parser.parse(response)
for position in statement.FlexStatements[0].OpenPositions:
if position.symbol.rstrip('z') == ticker:
Expand Down

0 comments on commit 8b1004a

Please sign in to comment.