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:
@@ -178,13 +178,13 @@ class BingXVenueAdapter:
|
||||
client_id = f"m_{state.ts_ns}_{self._order_seq}"
|
||||
|
||||
# Determine order type — use standardized OrderType, map to BingX-native
|
||||
from malkhut.training.order_types import normalize_to_exchange
|
||||
from malkhut.training.order_types import (
|
||||
normalize_type_to_exchange, normalize_tif_to_exchange,
|
||||
)
|
||||
if action.order_type is not None:
|
||||
order_type = normalize_to_exchange(action.order_type.value, "bingx") or "LIMIT"
|
||||
order_type = normalize_type_to_exchange(action.order_type, "bingx") or "LIMIT"
|
||||
elif action.kind.value == "CROSS_SPREAD":
|
||||
order_type = "MARKET"
|
||||
elif action.post_only:
|
||||
order_type = "POST_ONLY"
|
||||
else:
|
||||
order_type = "LIMIT"
|
||||
|
||||
@@ -197,8 +197,16 @@ class BingXVenueAdapter:
|
||||
"price": str(price),
|
||||
"quantity": str(qty),
|
||||
"reduceOnly": action.reduce_only,
|
||||
"postOnly": action.post_only,
|
||||
}
|
||||
|
||||
# Add timeInForce if not GTC (default)
|
||||
from malkhut.training.order_types import TimeInForce
|
||||
if action.time_in_force != "GTC":
|
||||
tif = normalize_tif_to_exchange(TimeInForce(action.time_in_force), "bingx")
|
||||
if tif:
|
||||
order["timeInForce"] = tif
|
||||
|
||||
# Track order
|
||||
tracked = TrackedOrder(
|
||||
client_order_id=client_id,
|
||||
|
||||
Reference in New Issue
Block a user