Portfolio mode not working
Description of the bug
When using the code with portfolio, it doesn’t return any open positions.
To Reproduce
Have open positions and run pytr portfolio to check them. You’ll see that it doesn’t display any.
Expected behavior
It should display the open positions.
Additional context
After inspecting the websocket directly from the Trade Republic web app and running some local tests, it seems they changed the endpoint.
It looks like they’re now using compactPortfolioByType instead of compactPortfolio.
Based on my tests, it seems to behave exactly the same, although I’m not sure what the previous one returned.
Does the issue still exist? What do you mean by open positions? I can see my portfolio of stocks and also my watchlist.
Does the issue still exist? What do you mean by open positions? I can see my portfolio of stocks and also my watchlist.
Yes! At least for my account.
If I try to see my portfolio (the stocks that I have), using the normal portfolio command that uses compactPortfolio I receive an empty result. But if I use compactPortfolioByType I'm able to see them.
If I check the websocket connection from the web it is using also compactPortfolioByType.
Do you want me to try something?
When using the default compactPortfolioByType I also failed to receive a portfolio update:
await tr._receive_one(tr.compact_portfolio(), timeout=5)
Returns: {'positions': []}
I logged in on the website and looked at the websocket traffic. It seems you now need to pass another argument
async def improved_compact_portfolio_by_type(
tr: TradeRepublicApi, secAccNo: str
) -> int:
return await tr.subscribe({"type": "compactPortfolioByType", "secAccNo": secAccNo})
await tr._receive_one(improved_compact_portfolio_by_type(tr, "********"), timeout=5)
Returns my entire portfolio.
I've created a PR (#256) that fixes this issue. The fix adds the secAccNo parameter to the compactPortfolio subscription request, extracting it from the account settings response (securitiesAccountNumber field). This should resolve the empty portfolio issue.