malkhut: urgency-driven maker/taker + calibrated slippage + chase + docs
This commit is contained in:
@@ -23,6 +23,10 @@ from malkhut.state import (
|
||||
from malkhut.actions import FulfilmentAction
|
||||
|
||||
|
||||
CHASE_MIN_OFFSET = 0 # minimum offset ticks for chase
|
||||
CHASE_MAX_OFFSET = 5 # maximum offset ticks for chase
|
||||
|
||||
|
||||
def _side_for_intent(intent_kind: IntentKind) -> Side:
|
||||
if intent_kind in (IntentKind.ENTER_LONG, IntentKind.ADD_LONG, IntentKind.REDUCE_SHORT, IntentKind.EXIT_SHORT):
|
||||
return Side.BUY
|
||||
@@ -107,8 +111,11 @@ def build_our_actions(
|
||||
post_only=intent.prefer_maker, reduce_only=intent.reduce_only,
|
||||
))
|
||||
|
||||
# Aggressive crossing if urgency allows
|
||||
if intent.urgency > 0.65:
|
||||
# Aggressive crossing — urgency-driven maker/taker decision
|
||||
# Below threshold: passive only (maker). Above: aggressive (taker).
|
||||
# The system learns the cheapest/fastest path as a function of urgency.
|
||||
if intent.urgency > params.urgency_taker_threshold:
|
||||
# High urgency: aggressive taker fills
|
||||
for frac in (0.05, 0.10, 0.25):
|
||||
actions.append(FulfilmentAction(
|
||||
kind=ActionKind.CROSS_SPREAD, side=side,
|
||||
@@ -116,7 +123,20 @@ def build_our_actions(
|
||||
qty_fraction=frac, ttl_ms=params.aggressive_ttl_ms,
|
||||
time_in_force="IOC",
|
||||
reduce_only=intent.reduce_only,
|
||||
metadata={"urgency": intent.urgency, "mode": "taker"},
|
||||
))
|
||||
elif intent.urgency > params.urgency_taker_threshold * 0.5:
|
||||
# Medium urgency: aggressive but with IOC (partial fill OK)
|
||||
for frac in (0.03, 0.06):
|
||||
actions.append(FulfilmentAction(
|
||||
kind=ActionKind.CROSS_SPREAD, side=side,
|
||||
order_type=OrderType.LIMIT, price_ticks_from_best=0,
|
||||
qty_fraction=frac, ttl_ms=params.aggressive_ttl_ms,
|
||||
time_in_force="IOC",
|
||||
reduce_only=intent.reduce_only,
|
||||
metadata={"urgency": intent.urgency, "mode": "taker_partial"},
|
||||
))
|
||||
# Low urgency: passive only (maker) — no taker actions added
|
||||
|
||||
# Path-risk exits
|
||||
if _path_risk_says_exit(state, params):
|
||||
@@ -127,4 +147,19 @@ def build_our_actions(
|
||||
metadata={"reason": "path_risk_exit"},
|
||||
))
|
||||
|
||||
# Chase actions (cancel → wait → retry with configurable wait_to_retry_ms)
|
||||
if params.chase_enabled and params.wait_to_retry_ms > 0:
|
||||
chase_ttl = params.wait_to_retry_ms
|
||||
for offset in range(CHASE_MIN_OFFSET, min(CHASE_MAX_OFFSET + 1, params.chase_offset_ticks + 1)):
|
||||
for frac in params.quote_size_fractions:
|
||||
actions.append(FulfilmentAction(
|
||||
kind=ActionKind.PLACE, side=side,
|
||||
order_type=OrderType.LIMIT,
|
||||
price_ticks_from_best=offset, qty_fraction=frac,
|
||||
ttl_ms=chase_ttl,
|
||||
post_only=True,
|
||||
metadata={"chase": True, "chase_offset": offset,
|
||||
"chase_max_retries": params.chase_max_retries},
|
||||
))
|
||||
|
||||
return tuple(actions)
|
||||
|
||||
Reference in New Issue
Block a user