Skip to content

Commit

Permalink
Added summary endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ystxn committed Jan 25, 2025
1 parent 18dce87 commit 014d236
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ibkr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pprint
from ibind import IbkrClient
import urllib3
import time
Expand Down Expand Up @@ -120,3 +121,12 @@ def get_positions(self):
return [self.clean_position(row) for row in data] + [cash_obj]

return [self.clean_row(row) for row in data] + [cash_obj]

def get_summary(self):
if not hasattr(self, 'account_id') or self.account_id is None:
self.account_id = self.client.portfolio_accounts().data[0]['id']
full_positions = self.client.positions(account_id = self.account_id).data
holdings = sum(item['mktValue'] for item in full_positions)
cash = self.client.portfolio_summary(account_id = self.account_id).data['availablefunds']['amount']
fx = self.client.live_marketdata_snapshot(conids = ['37928772'], fields = ['31']).data[0]['31']
return dict(fx = fx, broker = 'IBKR', brokerColour = 'd81222', holdings = holdings, cash = cash)
9 changes: 9 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ async def positions():
exc_info = sys.exc_info()
raise HTTPException(status_code=500, detail=''.join(traceback.format_exception(*exc_info)))

@app.get("/summary")
async def meta():
try:
return ibkr.get_summary()
except Exception:
exc_info = sys.exc_info()
raise HTTPException(status_code=500, detail=''.join(traceback.format_exception(*exc_info)))


app.mount("/", StaticFiles(directory="static", html = True), name="static")

0 comments on commit 014d236

Please sign in to comment.