Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pytr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ async def compact_portfolio(self):
self.settings()
if self._sec_acc_no is None:
raise ValueError("Could not retrieve securities account number from account settings.")
return await self.subscribe({"type": "compactPortfolio", "secAccNo": self._sec_acc_no})
return await self.subscribe({"type": "compactPortfolioByType", "secAccNo": self._sec_acc_no})

async def watchlist(self):
return await self.subscribe({"type": "watchlist"})
Expand Down
13 changes: 11 additions & 2 deletions pytr/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,18 @@ async def portfolio_loop(self):
while recv > 0:
subscription_id, subscription, response = await self.tr.recv()

if subscription["type"] == "compactPortfolio":
if subscription["type"] == "compactPortfolioByType":
recv -= 1
self.portfolio = response["positions"]
# New format: positions are grouped in categories[].positions
# Flatten all categories and normalize the field name: new API uses
# "isin" where the old "compactPortfolio" used "instrumentId".
positions = []
for cat in response.get("categories", []):
for pos in cat.get("positions", []):
if "isin" in pos and "instrumentId" not in pos:
pos["instrumentId"] = pos["isin"]
positions.append(pos)
self.portfolio = positions
elif subscription["type"] == "cash":
recv -= 1
self.cash = response
Expand Down