Add Firstrade session reuse and align notifications#11
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 26b7bf4dc4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| safe_username = "".join(ch for ch in self.credentials.username if ch.isalnum() or ch in ("-", "_")) | ||
| return cookie_dir / f"ft_session{safe_username}.json" |
There was a problem hiding this comment.
Derive session cache filename without username collisions
The cache filename strips every non-alphanumeric character from FIRSTRADE_USERNAME, so distinct usernames like alice.smith and alicesmith (or john+1 and john1) resolve to the same cache file. In a shared FIRSTRADE_COOKIE_DIR, the second account can load the first account’s ftat/sid and attempt to operate under the wrong session until fallback logic intervenes, which can misroute account selection and notifications. Use a collision-resistant encoding (e.g., URL-safe base64 or a hash of the raw username) instead of lossy character stripping.
Useful? React with 👍 / 👎.
Summary
This PR tightens Firstrade's notification/i18n behavior and adds an opt-in warm-instance session reuse layer.
The notification renderer now has an explicit execution-details block like the other US-equity platform repos, includes limit order price context, keeps the compact account/holding dashboard shape, and keeps zh/en keys aligned. Strategy signal/status localization from the previous fix remains in place, including small-account warning localization.
The Firstrade client can now reuse cached
ftat/sidsession headers from the local cookie directory whenFIRSTRADE_REUSE_SESSION=true. It validates the cached session by constructing account data before skipping login; if the session is expired or invalid, it deletes the cache and falls back to normal MFA login. The strategy cycle returns/logssession_reusedwithout exposing token values.Validation
.venv/bin/python -m pytest tests/test_firstrade_client.py tests/test_rebalance_service.py tests/test_request_handling.py -q.venv/bin/python -m py_compile application/firstrade_client.py application/rebalance_service.py application/execution_service.py notifications/telegram.py main.py.venv/bin/python -m pytest -q