Skip to content

Commit

Permalink
Allow init account id fetch to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
ystxn committed Nov 9, 2024
1 parent 5dcea27 commit e1dbbc0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ibkr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

class Ibkr:
def __init__(self, host='localhost'):
self.client = IbkrClient(host=host)
self.account_id = self.client.portfolio_accounts().data[0]['id']
print('Account ID:', self.account_id)
def __init__(self):
try:
self.client = IbkrClient(host='localhost')
self.account_id = self.client.portfolio_accounts().data[0]['id']
print('Account ID:', self.account_id)
except Exception:
print('Unable to fetch account ID')

def processK(self, val):
if 'K' in val:
Expand Down Expand Up @@ -94,6 +97,9 @@ def is_bad_data(self, data):
return all_daily_pnl_zero or any_ticker_missing

def get_positions(self):
if not hasattr(self, 'account_id') or self.account_id is None:
self.account_id = self.client.portfolio_accounts().data[0]['id']

attempts = 1
data = self.get_data()

Expand Down

0 comments on commit e1dbbc0

Please sign in to comment.