Skip to content

feat(orders): quantize margin-call liquidation lots to the symbol qty-step#48

Merged
luisleo526 merged 1 commit into
mainfrom
feat/margin-call-lot-quantization
Jun 30, 2026
Merged

feat(orders): quantize margin-call liquidation lots to the symbol qty-step#48
luisleo526 merged 1 commit into
mainfrom
feat/margin-call-lot-quantization

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

Refines the margin-call liquidation (PR #47) with TradingView's per-instrument lot quantization. TV floors each liquidation lot to the symbol's quantity step (verified: every TV margin-call lot for ETHUSDT.P is an exact 0.0004 multiple).

  • syminfo.qty_step (default 0.0 = disabled → corpus no-op), plumbed via the existing strategy_set_syminfo_metadata channel — no new C-ABI export (CI gate unaffected).
  • process_margin_call() floors the liquidation qty to the step (progress-guaranteed, position-capped) when qty_step_ > 0.
  • run_strategy.py reads runtime_overrides.qty_step.

Gates: corpus 251/1, byte-identical to HEAD with default (regenerated all 1628 corpus trade files → 0 lines differ); ctest 76/76 incl. a teeth-verified quantization test; C-ABI gate exit 0. With qty_step=0.0004: lots become exact 0.0004 multiples; abhivish 63.7→66.4%, pridarasx 79.9→80.8% (price-exact held).

🤖 Generated with Claude Code

…-step

TradingView floors each margin-call liquidation to the instrument's quantity
step (verified: every TV margin-call lot in the probe data is an exact multiple
of 0.0004 for ETHUSDT.P). The engine previously liquidated unquantized lots, so
its nibbles were slightly mis-sized and the per-call exit prices drifted from TV.

- syminfo gains qty_step (default 0.0 = disabled -> corpus no-op). Plumbed via the
  existing strategy_set_syminfo_metadata channel ("qty_step"), so NO new PF_API /
  C-ABI export is added (C-ABI CI gate unaffected).
- process_margin_call(): when qty_step_ > 0, floor the liquidation quantity down
  to the nearest qty_step multiple; if it floors to 0 while a call is required,
  liquidate min(qty_step, residual) to guarantee progress; cap at the full position.
- scripts/run_strategy.py reads runtime_overrides.qty_step into the metadata channel.

Validated: corpus verify_corpus --all = 251 excellent / 1 anomaly, byte-identical
to HEAD with default qty_step=0 (proven: regenerated all 1628 corpus trade files,
0 lines differ). ctest 76/76 incl. a new quantization test (teeth: mutating the
guard -> 4 failures). With qty_step=0.0004 the margin-call lots become exact
0.0004 multiples and abhivish strict match 63.7->66.4%, pridarasx 79.9->80.8%
(price-exactness held), confirming alignment with TV's per-instrument lot rows.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@luisleo526 luisleo526 merged commit 0df9812 into main Jun 30, 2026
5 checks passed
@luisleo526 luisleo526 deleted the feat/margin-call-lot-quantization branch June 30, 2026 11:11
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.

1 participant