Fix roll average entry: CTP trade-weighted avg, sync after fill, live entry for preview.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-30 10:42:56 +08:00
parent 6e954da4e1
commit e6208e403e
5 changed files with 239 additions and 68 deletions
+8 -1
View File
@@ -71,6 +71,7 @@ def check_roll_monitors(
fill_roll_leg_fn: Callable[[dict, dict, dict, dict], tuple[bool, str]],
is_trading_session_fn: Callable[[], bool],
get_risk_budget_fn: Callable[[], float],
get_entry_price_fn: Optional[Callable[[str, str, float], float]] = None,
) -> None:
"""扫描 pending 滚仓腿,标记价穿越则重算手数并市价成交。"""
if not is_trading_session_fn():
@@ -114,6 +115,12 @@ def check_roll_monitors(
"entry_price": leg["mon_entry"],
"take_profit": leg["mon_tp"] or leg["initial_take_profit"],
}
entry_fb = float(leg["mon_entry"] or 0)
entry_existing = (
get_entry_price_fn(sym, direction, entry_fb)
if get_entry_price_fn
else entry_fb
)
grp = {
"id": leg["roll_group_id"],
"order_monitor_id": leg["order_monitor_id"],
@@ -124,7 +131,7 @@ def check_roll_monitors(
direction=direction,
symbol=sym,
qty_existing=float(leg["mon_lots"] or 0),
entry_existing=float(leg["mon_entry"] or 0),
entry_existing=entry_existing,
initial_take_profit=float(leg["mon_tp"] or leg["initial_take_profit"] or 0),
add_mode=mode,
new_stop_loss=float(leg["new_stop_loss"] or 0),