Skip to content

Commit

Permalink
Improve retry
Browse files Browse the repository at this point in the history
  • Loading branch information
ystxn committed Nov 9, 2024
1 parent 61102b6 commit 5dcea27
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ibkr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ibind import IbkrClient
import urllib3
import time
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

class Ibkr:
Expand Down Expand Up @@ -87,11 +88,18 @@ def get_data(self):
for pos in positions
]

def is_bad_data(self, data):
all_daily_pnl_zero = all(row.get('dailyPnl', 0) == 0 for row in data)
any_ticker_missing = any('ticker' not in row for row in data)
return all_daily_pnl_zero or any_ticker_missing

def get_positions(self):
attempts = 0
attempts = 1
data = self.get_data()
while attempts < 3 and all(row.get('dailyPnl', 0) == 0 for row in data):
print('Bad data. Retry attempt:', attempts)

while attempts <= 3 and self.is_bad_data(data):
print('Bad data. Retry attempt', attempts)
time.sleep(1)
data = self.get_data()
attempts += 1

Expand Down

0 comments on commit 5dcea27

Please sign in to comment.