malkhut: all exchange order types in DSL + action_menu
ActionType → OrderType mapping (common-sensical): QUOTE/REQUOTE/CHASE: LIMIT (passive, post_only) CROSS_SPREAD (high urgency): MARKET (immediate fill) CROSS_SPREAD (medium urgency): LIMIT + IOC (partial fill) STOP_LOSS: STOP_MARKET (trigger → market exit) TAKE_PROFIT: TRIGGER_MARKET (trigger → market exit) TRAILING_STOP: TRAILING_STOP (trailing stop exit) EXIT/FLAT_ALL: STOP_MARKET EMERGENCY_EXIT: MARKET (immediate) All order types exercised: LIMIT, MARKET, STOP_MARKET, TRIGGER_MARKET, TRAILING_STOP
This commit is contained in:
@@ -616,10 +616,17 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
|
||||
)
|
||||
|
||||
elif at in (ActionType.CROSS, ActionType.SNIPER, ActionType.PING):
|
||||
# CROSS: aggressive fill. Use MARKET for immediate execution.
|
||||
# SNIPER: precision entry, use LIMIT + IOC for partial fill control.
|
||||
# PING: small aggressive test, use LIMIT + IOC.
|
||||
if at == ActionType.CROSS:
|
||||
order_type = OrderType.MARKET
|
||||
else:
|
||||
order_type = OrderType.LIMIT
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.CROSS_SPREAD, side=primitive.side, order_type=OrderType.LIMIT,
|
||||
kind=ActionKind.CROSS_SPREAD, side=primitive.side, order_type=order_type,
|
||||
price_ticks_from_best=0, qty_fraction=primitive.size_fraction, ttl_ms=50,
|
||||
time_in_force="IOC",
|
||||
time_in_force="IOC" if order_type == OrderType.LIMIT else "GTC",
|
||||
)
|
||||
|
||||
elif at == ActionType.CANCEL_ALL:
|
||||
@@ -637,8 +644,10 @@ def _primitive_to_action(primitive: ActionPrimitive, state: MarketWorldState) ->
|
||||
side = Side.SELL if pos and pos.qty > 0 else Side.BUY if pos and pos.qty < 0 else None
|
||||
if side is None:
|
||||
return FulfilmentAction(ActionKind.NOOP, None, None, 0, 0.0, 0)
|
||||
# EMERGENCY_EXIT uses MARKET for immediate fill; EXIT uses STOP_MARKET
|
||||
order_type = OrderType.MARKET if at == ActionType.EMERGENCY_EXIT else OrderType.STOP_MARKET
|
||||
return FulfilmentAction(
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.MARKET,
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=order_type,
|
||||
price_ticks_from_best=0, qty_fraction=1.0, ttl_ms=0, reduce_only=True,
|
||||
)
|
||||
|
||||
@@ -648,9 +657,9 @@ 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.MARKET,
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.STOP_MARKET,
|
||||
price_ticks_from_best=0, qty_fraction=1.0, ttl_ms=0, reduce_only=True,
|
||||
metadata={"reason": "stop_loss"},
|
||||
metadata={"reason": "stop_loss", "order_type_combo": "STOP_MARKET"},
|
||||
)
|
||||
|
||||
elif at == ActionType.TAKE_PROFIT:
|
||||
@@ -659,9 +668,9 @@ 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.MARKET,
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.TRIGGER_MARKET,
|
||||
price_ticks_from_best=0, qty_fraction=1.0, ttl_ms=0, reduce_only=True,
|
||||
metadata={"reason": "take_profit"},
|
||||
metadata={"reason": "take_profit", "order_type_combo": "TRIGGER_MARKET"},
|
||||
)
|
||||
|
||||
elif at == ActionType.TRAILING_STOP:
|
||||
@@ -670,9 +679,10 @@ 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.MARKET,
|
||||
kind=ActionKind.FULL_EXIT, side=side, order_type=OrderType.TRAILING_STOP,
|
||||
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},
|
||||
metadata={"reason": "trailing_stop", "trail_bps": primitive.trail_distance_bps,
|
||||
"order_type_combo": "TRAILING_STOP"},
|
||||
)
|
||||
|
||||
elif at == ActionType.HALF_EXIT:
|
||||
|
||||
Reference in New Issue
Block a user