Skip to content

fix(trading): complete native protection routing and safe reconciliation - #430

Merged
brokermr810 merged 137 commits into
mainfrom
test
Nov 29, 2026
Merged

brokermr810 merged 137 commits into
mainfrom
test

Conversation

@brokermr810

@brokermr810 brokermr810 commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Quick Trade could accept an entry while dropping trailing-stop parameters, losing protection intent on deferred fills, or reporting runtime-only markers as native protection. Some stock broker routes also accepted parameters that were never submitted to the broker.

Closes #428.
Builds on #429 by @PranavHariharan19. The original commit 76ea2139d15445d980e4fba879c115f70bde4ef4 was cherry-picked as 6eeec45b4c9dbad2a6263dc9022660176098b38c with its original author preserved; follow-up hardening remains in separate commits.

Changes

  • Carry and validate trailing ratios through the HTTP schema, Web, Agent, MCP and delayed-fill paths; update both API contracts.
  • Validate capabilities before entry. Binance, OKX, Bitget, Gate and HTX swaps support manual percentage trailing within venue limits. Reject impossible short activation prices before entry. Unsupported combinations fail explicitly.
  • Persist the crypto protection submission boundary before external writes; serialize reconciliation, protect only new fill quantities and retain successful legs when another fails. Uncertain writes require review instead of blind replay.
  • Preserve protection metadata during history, fee and cancellation updates, and expose asynchronous protection failures.
  • Add Gate/HTX native percentage trailing using filled contract quantities and verified HTX position mode.
  • Add IBKR/Tiger attached trailing to limit entries, Tiger fixed protection legs, and Webull whole-share fixed-protection combos.
  • Verify stock protective children independently of parent acceptance. Alpaca requests nested children and preserves accepted entries on read failure; Tiger queries children once; Webull matches response identities instead of assuming response order. Missing or uncertain child receipts remain unconfirmed, without replaying entry.
  • Expose venue-aware protection controls on desktop and mobile with localized copy, percentage conversion and incompatible-combination validation. Stock portfolio sells do not inherit opening protection.
  • Keep stock strategy protection runtime-owned by default. Bybit percentage trailing remains runtime-owned because its native absolute whole-position distance has different semantics; unsupported Binance/HTX native ratios remain explicitly runtime-owned.

Companion clients

Validation

  • Latest consolidated backend protection, broker, strategy-execution and receipt regression suite: 465 passed.
  • After adding the short-activation preflight fix, the affected contract suite passed all 63 tests, including 11 new cases. Counts overlap with the consolidated suite.
  • Desktop and mobile full unit suites passed; mobile: 282 tests. Mobile context refresh now explicitly awaits completion; its full suite and production build were rerun successfully.
  • SonarCloud quality gates passed on the final backend, desktop and mobile commits; backend CodeQL and DCO also passed.
  • Backend Ruff, structure, version and encoding checks passed. Desktop lint and locale completeness checks passed; both production builds passed.
  • Earlier PR validation included 133 strategy/native/manual-protection tests in an isolated Linux container and 104 HTTP/Agent/MCP contract tests.
  • The latest local Windows run cannot execute the 24 Linux network-isolated strategy sandbox cases; those require Linux CI. No real broker orders were submitted and no live-account certification is claimed.

Deployment and limits

No database migration. Deploy the backend and trading workers with both clients. Existing failed or uncertain protection must be reconciled against venue orders and remaining positions; do not repeat entry. Quick Trade has no local stop-monitor fallback; strategy runtime protection requires a running executor, usable quotes and an executable market session.

Stock broker protection uses broker order views, not the crypto Quick Trade journal. Tiger/Webull children use DAY validity and regular sessions; IBKR children use GTC. HTX uses optimal_20, which does not guarantee a complete fill. Query/cancel screens do not yet cover every new conditional-order family; use venue-side management for orders not listed locally.

Forthright native strategy orders are deferred. Standalone Alpaca/Webull trailing, Bybit distance-based position trailing and crypto spot OCO are separate integrations and are not implemented by this PR's attached-entry controls.

Attribution when merging

Retain the imported author commit when merging. If using squash merge, retain this trailer in the final commit:

Co-authored-by: Pranav pranavhariharanofficial@gmail.com

tianhe added 30 commits November 1, 2026 17:17
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>

# Conflicts:
#	backend_api_python/app/routes/community.py
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
tianhe and others added 20 commits November 28, 2026 01:21
Expose a restart-scoped 1-60 minute quote-age setting with a 16-minute default, align equity receipt expiry, retain provider timestamp and session checks, and document delayed-feed risks.

Validation: 215 focused backend tests passed; Ruff, backend quality, encoding and version checks passed.
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
The merged main tree exactly matches the pre-change test tree; preserve the verified quote-policy changes while recording merge ancestry.

Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: Prakash Jha <callmepnj@gmail.com>
(cherry picked from commit a5c7b82)
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
(cherry picked from commit 76ea213)
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
…paths

Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
@sonarqubecloud

Copy link
Copy Markdown

@brokermr810
brokermr810 merged commit eb575d9 into main Nov 29, 2026
19 checks passed
@brokermr810 brokermr810 mentioned this pull request Nov 29, 2026
5 of 9 tasks
MrRakun35 pushed a commit to MrRakun35/NovaTrade that referenced this pull request Nov 29, 2026
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.

Quick Trade drops trailing_stop_pct and trailing_activation_pct parameters and fails to attach native trailing protection

7 participants