Skip to content

Add Firstrade session reuse and align notifications#11

Merged
Pigbibi merged 1 commit into
mainfrom
firstrade-session-reuse-i18n
May 23, 2026
Merged

Add Firstrade session reuse and align notifications#11
Pigbibi merged 1 commit into
mainfrom
firstrade-session-reuse-i18n

Conversation

@Pigbibi

@Pigbibi Pigbibi commented May 23, 2026

Copy link
Copy Markdown
Contributor

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/sid session headers from the local cookie directory when FIRSTRADE_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/logs session_reused without 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

@Pigbibi Pigbibi merged commit 48b1ad8 into main May 23, 2026
1 check passed
@Pigbibi Pigbibi deleted the firstrade-session-reuse-i18n branch May 23, 2026 05:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +256 to +257
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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

1 participant