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:
@@ -609,15 +609,16 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
|
||||
elif at in (ActionType.QUOTE, ActionType.JOIN_QUEUE, ActionType.STEP_BACK,
|
||||
ActionType.LADDER, ActionType.GRID, ActionType.ICEBERG, ActionType.TWAP):
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.PLACE, side=primitive.side, order_type=OrderType.POST_ONLY,
|
||||
kind=ActionKind.PLACE, side=primitive.side, order_type=OrderType.LIMIT,
|
||||
price_ticks_from_best=primitive.offset_ticks, qty_fraction=primitive.size_fraction,
|
||||
ttl_ms=int(primitive.duration_s * 1000), post_only=True,
|
||||
)
|
||||
|
||||
elif at in (ActionType.CROSS, ActionType.SNIPER, ActionType.PING):
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.CROSS_SPREAD, side=primitive.side, order_type=OrderType.IOC,
|
||||
kind=ActionKind.CROSS_SPREAD, side=primitive.side, order_type=OrderType.LIMIT,
|
||||
price_ticks_from_best=0, qty_fraction=primitive.size_fraction, ttl_ms=50,
|
||||
time_in_force="IOC",
|
||||
)
|
||||
|
||||
elif at == ActionType.CANCEL_ALL:
|
||||
@@ -636,7 +637,7 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
|
||||
if side is None:
|
||||
return FulfilmentAction(ActionKind.NOOP, None, None, 0, 0.0, 0)
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.REDUCE_ONLY_MARKET,
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.MARKET,
|
||||
price_ticks_from_best=0, qty_fraction=1.0, ttl_ms=0, reduce_only=True,
|
||||
)
|
||||
|
||||
@@ -646,7 +647,7 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
|
||||
if side is None:
|
||||
return FulfilmentAction(ActionKind.NOOP, None, None, 0, 0.0, 0)
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.REDUCE_ONLY_MARKET,
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.MARKET,
|
||||
price_ticks_from_best=0, qty_fraction=1.0, ttl_ms=0, reduce_only=True,
|
||||
metadata={"reason": "stop_loss"},
|
||||
)
|
||||
@@ -657,7 +658,7 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
|
||||
if side is None:
|
||||
return FulfilmentAction(ActionKind.NOOP, None, None, 0, 0.0, 0)
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.REDUCE_ONLY_MARKET,
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.MARKET,
|
||||
price_ticks_from_best=0, qty_fraction=1.0, ttl_ms=0, reduce_only=True,
|
||||
metadata={"reason": "take_profit"},
|
||||
)
|
||||
@@ -668,7 +669,7 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
|
||||
if side is None:
|
||||
return FulfilmentAction(ActionKind.NOOP, None, None, 0, 0.0, 0)
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.REDUCE_ONLY_MARKET,
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.MARKET,
|
||||
price_ticks_from_best=0, qty_fraction=1.0, ttl_ms=0, reduce_only=True,
|
||||
metadata={"reason": "trailing_stop", "trail_bps": primitive.trail_distance_bps},
|
||||
)
|
||||
@@ -679,7 +680,7 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
|
||||
if side is None:
|
||||
return FulfilmentAction(ActionKind.NOOP, None, None, 0, 0.0, 0)
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.REDUCE, side=side, order_type=OrderType.REDUCE_ONLY_MARKET,
|
||||
kind=ActionKind.REDUCE, side=side, order_type=OrderType.MARKET,
|
||||
price_ticks_from_best=0, qty_fraction=0.5, ttl_ms=0, reduce_only=True,
|
||||
)
|
||||
|
||||
@@ -689,7 +690,7 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
|
||||
if side is None:
|
||||
return FulfilmentAction(ActionKind.NOOP, None, None, 0, 0.0, 0)
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.REDUCE, side=side, order_type=OrderType.REDUCE_ONLY_MARKET,
|
||||
kind=ActionKind.REDUCE, side=side, order_type=OrderType.MARKET,
|
||||
price_ticks_from_best=0, qty_fraction=0.25, ttl_ms=0, reduce_only=True,
|
||||
)
|
||||
|
||||
@@ -705,7 +706,7 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
|
||||
|
||||
elif at == ActionType.REQUOTE:
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.PLACE, side=primitive.side, order_type=OrderType.POST_ONLY,
|
||||
kind=ActionKind.PLACE, side=primitive.side, order_type=OrderType.LIMIT,
|
||||
price_ticks_from_best=primitive.offset_ticks, qty_fraction=primitive.size_fraction,
|
||||
ttl_ms=int(primitive.duration_s * 1000), post_only=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user