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

@@ -26,33 +26,23 @@ class Side(str, Enum):
class OrderType(str, Enum):
"""Standardized order types — FIX/CCXT-aligned, multi-exchange.
Five-layer taxonomy (values are uppercase for backward compatibility):
Layer 1: Base types (FIX Tag 40) — MARKET, LIMIT
Layer 2: Time-in-force (FIX Tag 59) — GTC, IOC, FOK, GTD
Layer 3: Conditional (FIX Tag 3/4+MIT) — STOP_MARKET, STOP_LIMIT, etc.
Layer 4: Instructions (FIX Tag 18) — POST_ONLY, REDUCE_ONLY, etc.
Layer 5: Compound (exchange-specific) — OCO, TP_SL
THREE ORTHOGONAL DIMENSIONS (not one flat enum):
1. Order Type (FIX Tag 40): what the order IS — this enum
2. TimeInForce (FIX Tag 59): how long it LIVES — separate parameter
3. Instructions (FIX Tag 18): behavioral modifiers — separate parameter
CRITICAL: IOC, FOK, POST_ONLY are NOT order types.
IOC/FOK = TimeInForce on a LIMIT order.
POST_ONLY = ExecInst modifier on a LIMIT order.
"""
# Layer 1: Base types (FIX Tag 40)
# Core order types (FIX Tag 40)
MARKET = "MARKET"
LIMIT = "LIMIT"
# Layer 2: Time-in-force (FIX Tag 59)
GTC = "GTC"
IOC = "IOC"
FOK = "FOK"
GTD = "GTD"
# Layer 3: Conditional (FIX Tag 3/4 + MIT)
STOP_MARKET = "STOP_MARKET"
STOP_LIMIT = "STOP_LIMIT"
TRIGGER_MARKET = "TRIGGER_MARKET"
TRIGGER_LIMIT = "TRIGGER_LIMIT"
TRAILING_STOP = "TRAILING_STOP"
# Layer 4: Instructions (FIX Tag 18)
POST_ONLY = "POST_ONLY"
REDUCE_ONLY = "REDUCE_ONLY"
HIDDEN = "HIDDEN"
ICEBERG = "ICEBERG"
# Layer 5: Compound (exchange-specific)
OCO = "OCO"
TP_SL = "TP_SL"