Skip to content

fix(brokers): reconcile Forthright execution fees and delayed fee recovery - #414

Merged
brokermr810 merged 109 commits into
mainfrom
test
Nov 27, 2026
Merged

brokermr810 merged 109 commits into
mainfrom
test

Conversation

@brokermr810

Copy link
Copy Markdown
Collaborator

Summary

  • Allocate Forthright securities' cumulative order fees across a complete, deduplicated set of executions before pagination. Verify symbol, market, side, currency, filled quantity and notional; preserve the exact total with a final rounding remainder and label the source as order_allocation.
  • Leave execution fees pending when order evidence is incomplete or unavailable, without hiding confirmed fills.
  • Include partially filled cancelled broker orders in delayed-fee reconciliation. Apply fee-only corrections to strategy runtime fill totals without replaying quantities or creating duplicate fills.
  • Document the fee semantics and coordinated rollout.

Root cause

Forthright exposes cumulative fees at the order level rather than on individual executions. Filled execution history therefore lacked fees; partially cancelled orders were excluded from later fee recovery, and fee-only updates did not update the strategy runtime fill projection.

Verification

  • Backend fee/Forthright/Alpaca-sync regression: 340 passed (two upstream exchange-calendar NumPy deprecation warnings).
  • Ruff, backend quality, repository encoding/version checks and diff checks passed.
  • Companion desktop unit suite: 861 passed; production build passed; lint passed with 0 errors and 1,407 existing warnings.
  • Companion mobile unit suite: 263 passed; production build passed.
  • Builds retain existing chunk-size warnings; desktop also reports outdated Browserslist data.

Companion changes

Deployment and remaining risk

  • No schema migration or manual historical-data rewrite. Deploy the API and trading worker together, with the companion desktop/mobile changes.
  • No production deployment or real broker orders were performed during verification. Fee allocation remains dependent on complete broker snapshots and may stay pending when evidence is incomplete.
  • Forthright futures transaction support is unchanged.
  • Synced the already-merged main ancestry after verifying it exactly matched the pre-change test tree; the history sync changed no files.

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

# Conflicts:
#	backend_api_python/app/routes/community.py
tianhe and others added 26 commits November 22, 2026 23:08
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/tests/integration/test_runtime_readiness.py
The grid resting-order audit (verify / re-reconcile in the UI) only read the
exchange open-orders snapshot. An order cancelled on the exchange was
reported as "not_open" forever and its local row stayed open, because the
worker fill poller only polls strategies with a live runner and the UI has
no delete action.

For rows absent from open orders, query the order itself (Binance
GET /fapi/v1/order via query_grid_order_fill) and report its terminal
status. An exchange-confirmed cancel with no fill is applied to the local
row through a guarded update; orders with fills are left to the fill
poller so no fill is dropped from the strategy ledger.

Fixes #404

(cherry picked from commit 46ef975)
Signed-off-by: TIANHE <[email protected]>
Build on PR #407 by preserving confirmed terminal-order lookup and adding asynchronous persisted verification, bounded recovery, stopped-grid accounting without follow-up orders, and regression coverage.

Co-authored-by: Pranav Tomar <[email protected]>
Signed-off-by: TIANHE <[email protected]>
Add scoped broker access, HK board-lot metadata, dated-futures manual trading, and credential redaction. Keep automated futures strategies disabled. Persist advertisement settings and generate their OpenAPI contract.

Signed-off-by: TIANHE <[email protected]>
The main tree matches the pre-fix test tree exactly. Record the squash-merge ancestry while preserving the verified broker fixes.

Signed-off-by: TIANHE <[email protected]>
The main tree exactly matches the pre-fix test tree. Record the merged ancestry while preserving the verified fee fixes.

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

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.49123% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ython/app/services/live_trading/fill_accounting.py 90.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@brokermr810
brokermr810 merged commit 6208b3a into main Nov 27, 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.

4 participants