feat(engine): add canonical risk and order matching
This commit is contained in:
parent
b65acccd91
commit
ccf333cc0a
13 changed files with 5129 additions and 36 deletions
|
|
@ -17,9 +17,20 @@ Implement canonical cash-long-only funding, pending fee-inclusive reservations,
|
|||
|
||||
No unrelated refactor, new service, broker enablement, or silent reinterpretation of historical results.
|
||||
|
||||
## Execution policy clarifications
|
||||
|
||||
The approved ADRs remain unchanged. The initial additive implementation pins these explicit configuration semantics; no default production thresholds or active-account migration are introduced:
|
||||
|
||||
- Quantity units for order/position limits; base-currency amounts for symbol/gross exposure, daily loss and explicitly named maximum drawdown amount. Commission is an immutable Rust rate in [0, 1], calculated from exact quantity × price × rate and rounded once at eight places.
|
||||
- Pending buys reserve fee-inclusive cash at the canonical mark (market) or max(mark, limit). Pending sells reserve owner inventory, never anticipated buying power; their fill proceeds fund fees. Pending sells do not offset buy exposure. Actual fills recheck other commitments and the remainder, including split-fill rounding. Unaffordable remainder rejects/releases without resizing or borrowing.
|
||||
- Increasing risk requires fresh non-future canonical marks across held and pending assets, using explicit engine event time and a configured maximum mark age. Reductions still enforce inventory/funding/order-size rules. Daily and drawdown halts latch on marked loss; explicit account boundaries reset only daily state, including when retained marks are old. Same-session repetition cannot rebase, and future/backdated boundaries reject.
|
||||
- A private-owned Ledger facade is the only canonical risk entry point. Normalized explicit-order and target-derived admission share one policy; actual target expansion, mode enforcement, matching, venue expiry scheduling and replay remain F05/F06. Resource-release hooks are not a second matcher.
|
||||
- Operator reset is a separate host-held capability with recorded reason/baseline, absent from strategy inputs. This is API authority separation, not authentication or an untrusted-code sandbox. F07 must expose only the risk-governed facade; later host/auth adapters must enforce their own authority.
|
||||
- Checkpoints validate reservations, risk state and recorded outcomes by deterministic reconstruction. They do not authenticate an attacker-modified history and are not full replay/strategy/RNG or SQL recovery snapshots. Normal transitions must not copy/replay the entire retained history.
|
||||
|
||||
## Likely files and ownership
|
||||
|
||||
- apps/stock/engine/src/risk/mod.rs
|
||||
- apps/stock/engine/src/risk/mod.rs (reference only during additive implementation)
|
||||
- apps/stock/engine/src/financial/risk.rs (new)
|
||||
- apps/stock/engine/src/financial/ledger.rs
|
||||
|
||||
|
|
@ -44,6 +55,7 @@ Parallel eligibility: only with disjoint actual files and reserved write locks;
|
|||
- competing_reservations, adverse_gap_reject_remainder, stale_other_symbol, marked_loss_halt, explicit_risk_session_boundary.
|
||||
- drawdown_halt_survives_rollover_restore, unauthorized_reset_denied, alternate_venue_does_not_reset_account_day.
|
||||
- Property test raw order and target paths cannot bypass the same policy.
|
||||
- Partial-fill quantum rounding, zero-cash funded sell, pending sells do not credit buy exposure, stale/future other pending symbol, wrong-owner sell/cancel, accepted/rejected command replay and conflicting reuse, same-session no-rebase, future/backdated boundary rejection, restored reservation tamper and overflow atomicity.
|
||||
|
||||
Apply relevant [quality gates](../../QUALITY-GATES.md). Report exact commands/results and unavailable checks; named new cases are requirements, not claims of existing passing tests.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue