malkhut: REQUOTE as proper CANCEL_REPLACE primitive + action_menu metadata

REQUOTE is now distinct from QUOTE:
  QUOTE: PLACE new order (no existing to cancel)
  REQUOTE: CANCEL_REPLACE existing + place new (immediate)
  CHASE: PLACE with short TTL (auto-cancel retry)
  CANCEL: Remove existing order

action_menu generates REQUOTE with metadata={'requote': True} for existing orders.
DSL REQUOTE produces CANCEL_REPLACE when existing order, falls back to PLACE.

All 800+ tests pass.
This commit is contained in:
Codex
2026-07-17 23:17:22 +02:00
parent 4926ef6788
commit 8322550fbc
2 changed files with 17 additions and 1 deletions

View File

@@ -98,6 +98,7 @@ def build_our_actions(
price_ticks_from_best=offset, qty_fraction=0.25, price_ticks_from_best=offset, qty_fraction=0.25,
ttl_ms=params.passive_ttl_ms, cancel_order_id=oo.client_order_id, ttl_ms=params.passive_ttl_ms, cancel_order_id=oo.client_order_id,
post_only=intent.prefer_maker, reduce_only=intent.reduce_only, post_only=intent.prefer_maker, reduce_only=intent.reduce_only,
metadata={"requote": True, "requote_offset": offset},
)) ))
# Passive quote placements # Passive quote placements

View File

@@ -706,10 +706,25 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
return FulfilmentAction(ActionKind.NOOP, None, None, 0, 0.0, 0) return FulfilmentAction(ActionKind.NOOP, None, None, 0, 0.0, 0)
elif at == ActionType.REQUOTE: elif at == ActionType.REQUOTE:
# Requote: cancel existing order and place a new one at target offset.
# The CANCEL_REPLACE action handles both cancel + place in a single step.
# This is distinct from QUOTE (place new) and CHASE (place + wait + auto-cancel).
if state.open_orders:
oo = state.open_orders[0]
return FulfilmentAction(
kind=ActionKind.CANCEL_REPLACE, side=primitive.side, order_type=OrderType.LIMIT,
price_ticks_from_best=primitive.offset_ticks, qty_fraction=primitive.size_fraction,
ttl_ms=0, # Replaced order has no TTL (stays until next cancel/requote)
post_only=True,
cancel_order_id=oo.client_order_id,
metadata={"requote": True, "requote_offset": primitive.offset_ticks},
)
# No existing order — fall back to PLACE
return FulfilmentAction( return FulfilmentAction(
kind=ActionKind.PLACE, side=primitive.side, order_type=OrderType.LIMIT, kind=ActionKind.PLACE, side=primitive.side, order_type=OrderType.LIMIT,
price_ticks_from_best=primitive.offset_ticks, qty_fraction=primitive.size_fraction, price_ticks_from_best=primitive.offset_ticks, qty_fraction=primitive.size_fraction,
ttl_ms=int(primitive.duration_s * 1000), post_only=True, ttl_ms=0, post_only=True,
metadata={"requote": True, "requote_offset": primitive.offset_ticks, "fallback": True},
) )
elif at == ActionType.CHASE: elif at == ActionType.CHASE: