Skip to content

fix(trading): keep confirmed exchange order P&L available - #400

Merged
brokermr810 merged 80 commits into
mainfrom
test
Nov 21, 2026
Merged

brokermr810 merged 80 commits into
mainfrom
test

Conversation

@brokermr810

Copy link
Copy Markdown
Collaborator

Root cause

Confirmed order P&L was saved in qd_exchange_order_pnl, but the read path discarded it after five minutes. Refresh limits or venue failures then made persisted results appear pending.

Changes

  • Reuse confirmed reports while their quantity matches recorded fills, without time-based expiry.
  • Preserve bounded reconciliation for missing reports and changed quantities.
  • Show split-fill order totals once; keep venue P&L separate from strategy accounting.
  • Add regression tests and update English/Chinese safety documentation.

Verification

  • 202 related unit tests passed.
  • 19 PostgreSQL integration tests passed in an isolated disposable database, including saved-report reuse after one day.
  • Ruff, backend structural checks, documentation checks and git diff --check passed.
  • New commits include DCO sign-off; merging main did not change the tested final tree.

Deployment and scope

Backend update only. No new migration, historical rewrite, frontend change or trading/exchange mutation. Missing or quantity-incomplete reports still require complete reconciliation evidence. Production has not been deployed and CI is not yet confirmed.

tianhe added 30 commits November 1, 2026 17:17
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/app/routes/community.py
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/tests/test_safe_exec.py
#	backend_api_python/tests/test_strategy_runtime_process_isolation.py
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/app/professional_report/features/equity.py
#	backend_api_python/app/research/workflows.py
#	backend_api_python/tests/test_professional_report_builder.py
…emails

Persist definitive order failure streaks and portfolio batch outcomes, send deduplicated alerts across opted-in channels, and render transactional emails using localized monochrome templates and configured branding.

Signed-off-by: TIANHE <[email protected]>
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/app/services/strategy_v2/live_execution.py
#	backend_api_python/app/services/trading_executor.py
#	backend_api_python/tests/test_strategy_v2_order_gateway.py
#	docs/trading/LIVE_TRADING_SAFETY.md
#	docs/trading/LIVE_TRADING_SAFETY_CN.md
Use the canonical strategy_name column for automatic-stop and rebalance notifications, honor explicit stop-and-close requests, and exercise the production schema and notification delivery paths in regression tests.

Signed-off-by: TIANHE <[email protected]>
Keep order sizing aligned with the deployment ledger across restarts. Revalue positions atomically with fills and derive live floating PnL from current quantities so stale residual rows cannot inflate equity. Preserve real small holdings and add cross-path regression coverage.

Signed-off-by: TIANHE <[email protected]>
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	docs/trading/LIVE_TRADING_SAFETY.md
#	docs/trading/LIVE_TRADING_SAFETY_CN.md
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@brokermr810
brokermr810 merged commit 0266c6b into main Nov 21, 2026
15 checks passed
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.

3 participants