From 56259710dac797edf651a2f4a0376c1bf5891252 Mon Sep 17 00:00:00 2001 From: Patrick Ruckstuhl Date: Tue, 28 Jul 2020 06:50:22 +0000 Subject: [PATCH] deal with throttling from ibkr when fetching prices --- src/tariochbctools/plugins/prices/ibkr.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tariochbctools/plugins/prices/ibkr.py b/src/tariochbctools/plugins/prices/ibkr.py index cec7655..bd382a7 100644 --- a/src/tariochbctools/plugins/prices/ibkr.py +++ b/src/tariochbctools/plugins/prices/ibkr.py @@ -4,6 +4,7 @@ from os import environ from ibflex import client, parser from datetime import datetime +from time import sleep class Source(source.Source): @@ -11,7 +12,15 @@ 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: