malkhut(wire): 5 risk gate stubs implemented + 3 scenarios behavior-driven
Risk gate (risk/gate.py) — 5 stubs implemented: 1. _kill_switch_active(): operator-controlled emergency stop via set_kill_switch() 2. _cancel_rate_would_exceed(): tracks cancel timestamps per symbol in 60s sliding window, blocks if >= MAX_CANCELS_PER_SYMBOL_PER_MINUTE 3. _would_self_trade(): checks open orders for same symbol+side at same price (within tick_size), skipping the cancel_order_id for CANCEL_REPLACE 4. _would_exceed_symbol_notional(): sums current open order notional + new order notional, blocks if > equity * MAX_SYMBOL_NOTIONAL_FRACTION 5. _violates_venue_minima(): checks tick alignment, lot rounding, min_qty, and min_notional — all float-robust comparisons ScenarioFactory — 3 remaining hardcoded scenarios converted: 1. _spread_tightening: spread_mult=0.3, depth_fraction=1.0 (was hardcoded BTC) 2. _cross_venue_arb: spread_mult=0.5, depth_fraction=0.5 (was hardcoded BTC) 3. _cross_exchange_arb_stress: spread_mult=0.8, depth_fraction=0.3 (was hardcoded BTC) All 30 scenarios now use _behavior_state() — zero hardcoded prices remain. 675 tests pass. Zero regressions.
This commit is contained in:
@@ -645,7 +645,7 @@ class ScenarioFactory:
|
||||
return Scenario(
|
||||
scenario_id=f"tighten_{symbol}_{seed}",
|
||||
symbol=symbol,
|
||||
initial_state=self._make_state(symbol, bid=49950.0, ask=50050.0, bid_qty=2.0, ask_qty=2.0, exchange_id=self.exchange_id),
|
||||
initial_state=self._behavior_state(symbol, spread_mult=0.3, depth_fraction=1.0, exchange_id=self.exchange_id),
|
||||
counterparties=self.counterparties,
|
||||
max_steps=steps,
|
||||
tags=("spread_tightening", "competition"),
|
||||
@@ -726,7 +726,7 @@ class ScenarioFactory:
|
||||
return Scenario(
|
||||
scenario_id=f"arb_{symbol}_{seed}",
|
||||
symbol=symbol,
|
||||
initial_state=self._make_state(symbol, bid=49990.0, ask=50010.0, bid_qty=0.5, ask_qty=0.5, exchange_id=self.exchange_id),
|
||||
initial_state=self._behavior_state(symbol, spread_mult=0.5, depth_fraction=0.5, exchange_id=self.exchange_id),
|
||||
counterparties=(LatencyArbPolicy(lead_threshold=0.3), ToxicTakerPolicy(sensitivity=0.4)),
|
||||
max_steps=steps,
|
||||
tags=("arbitrage", "cross_venue", "price_discovery"),
|
||||
@@ -834,7 +834,7 @@ class ScenarioFactory:
|
||||
return Scenario(
|
||||
scenario_id=f"arb_stress_{symbol}_{seed}",
|
||||
symbol=symbol,
|
||||
initial_state=self._make_state(symbol, bid=49980.0, ask=50020.0, bid_qty=0.3, ask_qty=0.3, exchange_id=self.exchange_id),
|
||||
initial_state=self._behavior_state(symbol, spread_mult=0.8, depth_fraction=0.3, exchange_id=self.exchange_id),
|
||||
counterparties=(LatencyArbPolicy(lead_threshold=0.2), ToxicTakerPolicy(sensitivity=0.4)),
|
||||
max_steps=steps,
|
||||
tags=("cross_exchange", "arb_stress", "price_discovery"),
|
||||
|
||||
Reference in New Issue
Block a user