feat(orders): quantize margin-call liquidation lots to the symbol qty-step#48
Merged
Merged
Conversation
…-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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 existingstrategy_set_syminfo_metadatachannel — no new C-ABI export (CI gate unaffected).process_margin_call()floors the liquidation qty to the step (progress-guaranteed, position-capped) whenqty_step_ > 0.run_strategy.pyreadsruntime_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