Skip to content

fix: harden trading recovery and research reports; optimize runtime reads - #403

Merged
brokermr810 merged 88 commits into
mainfrom
test
Nov 22, 2026
Merged

brokermr810 merged 88 commits into
mainfrom
test

Conversation

@brokermr810

@brokermr810 brokermr810 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Paginate trade-history responses while retaining complete-ledger FIFO fee allocation, grid pairing, and strategy-wide totals.
  • Read saved venue P&L during HTTP requests and queue bounded missing-report backfills on the maintenance worker instead of waiting for exchange REST.
  • Add incremental bounded log reads and indexed latest-run, health, event, and fill lookups.
  • Preserve tenant isolation, runtime-generation fencing, and live/virtual accounting boundaries.

Root cause

History requests waited for external venue calls and repeatedly returned complete histories. Runtime health reads processed historical rows where only current/latest records were needed.

Verification

  • 182 targeted backend tests passed during implementation, including PostgreSQL 18 integration tests and an EXPLAIN ANALYZE assertion for indexed latest-event reads.
  • Ruff, backend quality checks, documentation checks, and diff checks passed during implementation.
  • Companion desktop commit: OpenByteInc/QuantDinger-Vue@274f754; 752 unit tests and production build passed. Six focused history tests and touched-file ESLint passed again before commit.
  • Synced main into test and verified the final file tree matches the tested optimization commit.

Deployment and compatibility

  • Deploy backend, the regular Celery maintenance worker, and companion desktop update together.
  • Apply registered migration 20261122_strategy_history_read_indexes.sql. Index creation can temporarily block writes and generate I/O; schedule accordingly.
  • Legacy clients without pagination/cursor parameters retain their existing contract.
  • No deployment or historical-data deletion/compaction has been performed.

Remaining scope

Complete ledger context is still read for accounting before pagination; this is not constant-time SQL pagination. Historical backtest curve compaction and reusable accounting summaries are separate follow-ups.

Additional changes - 2026-11-23

Trading recovery (1c48928)

  • Retry only explicit safe rejections using bounded backoff and stable client order IDs. Ambiguous submission outcomes are reconciled rather than blindly resubmitted.
  • Persist grid submission intent before network calls; prevent late acknowledgements from regressing fills.
  • Preserve protective exits during snapshot/ledger outages and require fresh allocation evidence before cancel/rebuild.
  • Fail closed on malformed position snapshots; improve broker and exchange recovery. Centralize broker routing to stay within the worker file-size budget.
  • Update English/Chinese trading safety documentation and add PostgreSQL concurrency/rollback regressions.

Research reports (5b1af76)

  • Normalize CN/HK/US fundamentals with explicit fiscal periods, units, currency, and provenance; keep crypto applicability separate.
  • Add bounded attributable asset news and issuer disclosures, with caching, timestamps, restricted document hosts, and parsing limits.
  • Separate news availability from positioning sentiment; distinguish provider gaps from poor issuer fundamentals.
  • Expose event sources, evidence depth, and partial coverage in localized desktop/mobile reports.

Verification for this update

  • 473 targeted backend tests passed. The 8 PostgreSQL-dependent tests skipped in that run were subsequently run against isolated PostgreSQL 18: all 8 passed.
  • After the broker helper extraction, 75 additional focused broker/worker/retry tests passed (overlapping suites, not an additive unique-test count).
  • Ruff, backend quality/file-size checks, requirements-lock validation, documentation checks, diff checks, and staged secret scans passed.
  • Desktop: 8 report locale tests, touched-file ESLint, and production build passed.
  • Mobile: 5 report locale tests and report SFC script/template compilation passed.
  • Mobile full build remains unverified locally: Node 20.12.2 is below Vite's supported version and the local dependency tree cannot resolve @fontsource-variable/source-serif-4. No unrelated dependency or lockfile changes were made.
  • No live orders, existing-service restarts, or production-database operations were performed.

Companion commits

Deployment and remaining risks

  • Deploy backend/runtime workers and companion frontends together as appropriate; the prior history-index migration and maintenance-worker requirements above still apply.
  • New bounded retry defaults are documented in .env.example and Compose. Ambiguous submissions remain non-retryable.
  • External news/disclosure coverage remains provider-dependent; unavailable/partial evidence is represented explicitly.
  • New commits carry DCO sign-offs. No merge or deployment has been performed.

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/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
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/tests/integration/test_runtime_readiness.py
@brokermr810 brokermr810 changed the title perf(runtime): reduce strategy history and health loading overhead fix: harden trading recovery and research reports; optimize runtime reads Nov 22, 2026
@sonarqubecloud

Copy link
Copy Markdown

@brokermr810
brokermr810 merged commit 8090605 into main Nov 22, 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