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

@@ -86,14 +86,14 @@ def _noop():
def _place(side, offset=0, frac=0.1, post_only=False, reduce_only=False):
return FulfilmentAction(
ActionKind.PLACE, side,
OrderType.POST_ONLY if post_only else OrderType.LIMIT,
OrderType.LIMIT if post_only else OrderType.LIMIT,
offset, frac, 200,
post_only=post_only, reduce_only=reduce_only,
)
def _cross(side, frac=0.1):
return FulfilmentAction(ActionKind.CROSS_SPREAD, side, OrderType.IOC, 0, frac, 50)
return FulfilmentAction(ActionKind.CROSS_SPREAD, side, OrderType.LIMIT, 0, frac, 50)
def _cancel(order_id):
@@ -103,7 +103,7 @@ def _cancel(order_id):
def _oo(cid="c1", price=50000.0, qty=0.001, side=Side.BUY, ts=1_000_000_000):
return OpenOrderState(
client_order_id=cid, venue_order_id="v1", symbol="BTCUSDT",
side=side, order_type=OrderType.POST_ONLY, price=price,
side=side, order_type=OrderType.LIMIT, price=price,
qty=qty, remaining_qty=qty, queue_ahead_estimate=qty * 0.5,
created_ts_ns=ts, last_update_ts_ns=ts, post_only=True,
)