malkhut(wire): OrderType as three orthogonal dimensions — Fable's corrections

CRITICAL REFACTOR based on Fable's review (S9 roadmap item):

Before: flat enum conflating order types with TIF/instructions
  OrderType had MARKET, LIMIT, IOC, FOK, POST_ONLY, REDUCE_ONLY, etc.

After: three orthogonal dimensions (FIX-aligned):
  1. OrderType (Tag 40): what the order IS
     LIMIT, MARKET, STOP_MARKET, STOP_LIMIT, TRIGGER_MARKET, TRIGGER_LIMIT,
     TRAILING_STOP, OCO, TP_SL
  2. TimeInForce (Tag 59): how long it LIVES
     GTC, IOC, FOK, GTD
  3. Instructions (Tag 18): behavioral modifiers
     POST_ONLY, REDUCE_ONLY, HIDDEN, ICEBERG

Key corrections:
- POST_ONLY is an instruction on a LIMIT order, not a standalone type
- IOC/FOK are TimeInForce values, not order types
- BingX trailing_stop -> native TRAILING_STOP_MARKET (not TRIGGER_MARKET)
- FulfilmentAction.time_in_force: new field, default GTC

Exchange mappings restructured:
  EXCHANGE_ORDER_TYPE_MAP: OrderType -> exchange native 'type' param
  EXCHANGE_TIF_MAP: TimeInForce -> exchange native 'timeInForce' param
  EXCHANGE_INSTRUCTION_MAP: Instruction -> exchange encoding

21 files changed. 380+ tests pass. Backward compatible.
This commit is contained in:
Codex
2026-07-14 14:46:44 +02:00
parent a21f64e066
commit d24d9bc6bd
21 changed files with 346 additions and 199 deletions

View File

@@ -90,7 +90,7 @@ def build_our_actions(
for offset in params.quote_offsets_ticks:
actions.append(FulfilmentAction(
kind=ActionKind.CANCEL_REPLACE, side=side,
order_type=OrderType.POST_ONLY if intent.prefer_maker else OrderType.LIMIT,
order_type=OrderType.LIMIT,
price_ticks_from_best=offset, qty_fraction=0.25,
ttl_ms=params.passive_ttl_ms, cancel_order_id=oo.client_order_id,
post_only=intent.prefer_maker, reduce_only=intent.reduce_only,
@@ -101,7 +101,7 @@ def build_our_actions(
for frac in params.quote_size_fractions:
actions.append(FulfilmentAction(
kind=ActionKind.PLACE, side=side,
order_type=OrderType.POST_ONLY if intent.prefer_maker else OrderType.LIMIT,
order_type=OrderType.LIMIT,
price_ticks_from_best=offset, qty_fraction=frac,
ttl_ms=params.passive_ttl_ms,
post_only=intent.prefer_maker, reduce_only=intent.reduce_only,
@@ -112,8 +112,9 @@ def build_our_actions(
for frac in (0.05, 0.10, 0.25):
actions.append(FulfilmentAction(
kind=ActionKind.CROSS_SPREAD, side=side,
order_type=OrderType.IOC, price_ticks_from_best=0,
order_type=OrderType.LIMIT, price_ticks_from_best=0,
qty_fraction=frac, ttl_ms=params.aggressive_ttl_ms,
time_in_force="IOC",
reduce_only=intent.reduce_only,
))