Skip to content

fix: preserve commissioned all-in opening lots - #124

Merged
luisleo526 merged 1 commit into
mainfrom
codex/z8830-margin-quantize-once
Jul 20, 2026
Merged

fix: preserve commissioned all-in opening lots#124
luisleo526 merged 1 commit into
mainfrom
codex/z8830-margin-quantize-once

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

Summary

This carries two independently evidenced broker/runtime fixes atomically:

  • when a commissioned, omitted-qty, 100%-of-equity, true-flat MARKET long is affordable before its percentage opening fee but that fee alone creates a positive sub-lot margin deficit, preserve TradingView's one-contract floor-zero liquidation fallback (capped by the live position)
  • treat an already-frozen default MARKET quantity as pre-quantized on the actual-flat fill path, so an exact binary lot is not floored a second time

The first fix exposes the second one. Either patch alone leaves the source Strong; only the pair is regression-free and promotes the target.

Exhaustive 2^2

All four cells used identical source, TradingView tape, feeds, generated C++, and semantic route (qty_step=0.0001, asia_taipei):

Cell Raw matched / TV Tier PnL P90
baseline 955 / 979 Strong 2.6870%
quantize-once only 955 / 979 Strong 2.6792%
margin fallback only 962 / 979 Strong 5.0159%
both 979 / 979 Excellent 0.0000%

The all-on target is exact: canonical match 100%, count/entry/exit/PnL errors all zero. Three baseline-Excellent sentinels remain Excellent; the related KI-57 Strong control remains stable.

Causal anchors

  • 2025-04-04 14:00 UTC: opening commission alone creates raw q_min=0.000010904...; ordinary lot flooring returns zero, while TV emits a 1-contract Margin call
  • after that is fixed, 2025-04-07 exposes the independent second floor: TV 6.2790, one-factor engine 6.2789, paired fix 6.2790
  • the TV tape repeats the margin edge 25 times: one ordinary 0.0004 fragment, twenty-two 1-contract fallbacks, and two sub-one full-position caps

Scope controls

The fallback requires exact true-flat omitted-qty high-level MARKET-long provenance, PoE=100, margin=100, admitted frozen sizing, and positive percentage commission. Explicit/priced/RAW/add/reversal/short/zero/CASH/off-grid cases remain outside it. The event flag is consumed before early returns and reset on every flat/fresh/raw/stale path.

A separate 8-case / 58-assertion private QA suite covers two consecutive position cycles, all exclusions above, and directional pre-fee headroom. +0.3000 triggers; -5.7645 does not, so replacing direction with abs(difference) would be incorrect here.

Tests

  • baseline-red F1 regression: 289/299; candidate 299/299
  • baseline/F1-red quantize-once regression: 45/48 (6.2789 vs 6.2790); C/F1+C 48/48
  • independent focused suites: 1,655/1,655
  • fresh full Release CTest: 112/112
  • ASan+UBSan focused margin/freeze/reset lane: 3/3
  • committed-candidate fixed-feed rerun: z8830 979/979 and Excellent; all four controls unchanged

Final binary diff SHA-256: ac994009bf2877d1c49a622f75025a723efef130c6f1e22c52b3192bf4dbafbc.

No new TradingView export or public corpus probe is included.

@luisleo526
luisleo526 marked this pull request as ready for review July 20, 2026 07:00
@luisleo526
luisleo526 merged commit 76e8097 into main Jul 20, 2026
7 checks passed
@luisleo526
luisleo526 deleted the codex/z8830-margin-quantize-once branch July 20, 2026 07:00
@nitumamon

nitumamon commented Jul 20, 2026 via email

Copy link
Copy Markdown

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.

2 participants