pytr icon indicating copy to clipboard operation
pytr copied to clipboard

Portfolio mode not working

Open xurxofp opened this issue 2 months ago • 4 comments

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.

xurxofp avatar Oct 13 '25 22:10 xurxofp

Does the issue still exist? What do you mean by open positions? I can see my portfolio of stocks and also my watchlist.

RealCLanger avatar Oct 15 '25 18:10 RealCLanger

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?

xurxofp avatar Oct 15 '25 21:10 xurxofp

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.

ganzinotti avatar Oct 27 '25 20:10 ganzinotti

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.

maximilian-sh avatar Nov 06 '25 12:11 maximilian-sh