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:
@@ -333,6 +333,7 @@ class MinimalCryptoLOBCWM:
|
||||
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(
|
||||
@@ -356,6 +357,17 @@ class MinimalCryptoLOBCWM:
|
||||
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]
|
||||
|
||||
# 1b. TTL enforcement — auto-cancel expired open orders (CHASE mechanic)
|
||||
if open_orders:
|
||||
alive = []
|
||||
for oo in open_orders:
|
||||
age_ms = (now_ts - oo.created_ts_ns) / 1_000_000
|
||||
ttl = getattr(oo, 'ttl_ms', 0)
|
||||
if ttl > 0 and age_ms >= ttl:
|
||||
continue # expired
|
||||
alive.append(oo)
|
||||
open_orders = alive
|
||||
|
||||
# 2. Process counterparty cancels
|
||||
for cp in counterparty_actions:
|
||||
if isinstance(cp, CounterpartyAction) and cp.kind.value == "CANCEL":
|
||||
|
||||
Reference in New Issue
Block a user