Skip to content

Conversation

@maximilian-sh
Copy link

@maximilian-sh maximilian-sh commented Nov 6, 2025

Fixes #246

Description

The Trade Republic API now requires the secAccNo (securities account number) parameter for the compactPortfolio subscription. This PR fixes the issue where portfolio mode was not returning any positions.

Changes

  • Added private _secAccNo attribute to TradeRepublicApi class
  • Enhanced settings() method to extract secAccNo from settings_data["securitiesAccountNumber"]
  • Updated compact_portfolio() method to include secAccNo in the subscription request
  • Added compact_portfolio_by_type() method for completeness (as mentioned in the issue)

Testing

  • Tested with web login session
  • Confirmed v0.4.5 (without fix) returns empty portfolio
  • Confirmed this branch correctly retrieves all portfolio positions
  • securitiesAccountNumber field is present in the /api/v2/auth/account response

Related

Based on findings from @ganzinotti in issue #246.

pytr/api.py Outdated
_subscription_id_counter = 1
_previous_responses: Dict[str, str] = {}
subscriptions: Dict[str, Dict[str, Any]] = {}
secAccNo = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this private

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, renamed to _secAccNo.

self.secAccNo = account["id"]
break
return settings_data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all these locations still relevant to try?

In my case the securities account number is stored in settings_data["securitiesAccountNumber"]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — simplified to only use settings_data["securitiesAccountNumber"]. The other fallbacks were speculative. Same field works for me as well.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@maximilian-sh maximilian-sh force-pushed the fix/portfolio-secaccno-246 branch from cbfe507 to d43535b Compare February 1, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Portfolio mode not working

2 participants