malkhut: CHASE mechanics FIXED + Flight9 learnings + TTL enforcement

1. CHASE mechanics (NOW WORKING):
   - CWM enforces TTL on open orders (auto-cancel when expired)
   - DSL CHASE produces PLACE with metadata={chase: True}
   - Action menu generates chase actions with wait_to_retry_ms TTL
   - OpenOrderState.gains ttl_ms field (0=no expiry, >0=auto-cancel)

2. TTL enforcement (CWM):
   - HftBacktestCWM: auto-cancels orders where age >= ttl_ms
   - MinimalCryptoLOBCWM: same TTL enforcement
   - This is how CHASE works: place→wait→auto-cancel→next step re-places

3. Flight9 learnings:
   - Slippage model gains trade_flow_intensity parameter
   - Book imbalance as proxy for trade arrival rate
   - Markout = quality concept documented

4. CHASE tests: 10 new tests covering TTL enforcement, cancel-retry cycle,
   max retries, DSL CHASE action, CMA codec integration

5. All 800+ tests pass
This commit is contained in:
Codex
2026-07-17 19:30:17 +02:00
parent bb229833d3
commit 4926ef6788
5 changed files with 125 additions and 1 deletions

View File

@@ -202,6 +202,7 @@ class HftBacktestCWM:
last_update_ts_ns=ts,
reduce_only=action.reduce_only,
post_only=action.post_only,
ttl_ms=action.ttl_ms if action.ttl_ms > 0 else 0,
)
def transition(
@@ -225,7 +226,22 @@ class HftBacktestCWM:
if our_action.kind.value == "CANCEL_REPLACE" and our_action.cancel_order_id:
open_orders = [o for o in open_orders if o.client_order_id != our_action.cancel_order_id]
# 2. Process counterparty cancels
# 2. TTL enforcement — auto-cancel expired open orders (CHASE mechanic)
# Orders with ttl_ms > 0 expire after ttl_ms. This is how CHASE works:
# place → wait → auto-cancel → next step re-places at new offset.
if open_orders:
alive = []
for oo in open_orders:
age_ms = (now_ts - oo.created_ts_ns) / 1_000_000
if oo.last_update_ts_ns > oo.created_ts_ns:
age_ms = (now_ts - oo.last_update_ts_ns) / 1_000_000
ttl = oo.ttl_ms
if ttl > 0 and age_ms >= ttl:
continue # expired — auto-cancel
alive.append(oo)
open_orders = alive
# 3. Process counterparty cancels
for cp in counterparty_actions:
if isinstance(cp, CounterpartyAction) and cp.kind.value == "CANCEL":
open_orders = [o for o in open_orders if o.symbol != state.venue.symbol]