fix(trend): use money RR, track DCA fills, snapshot before close

Align running-plan header and DCA table with risk-budget RR, record actual fill prices after each leg, and save pre-close snapshots on stop/TP/handoff across hub and exchanges.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-07 17:34:50 +08:00
parent 84abf7e7f7
commit d56d9050aa
7 changed files with 268 additions and 87 deletions
+19 -3
View File
@@ -3976,9 +3976,21 @@ def enrich_active_trend_plan_row(row):
d["floating_mark"] = float(m["mark_price"])
else:
d["floating_mark"] = None
try:
d["contract_size"] = float(get_contract_size(ex_sym))
except (TypeError, ValueError):
pass
from strategy_snapshot_lib import attach_trend_dca_levels
from strategy_trend_lib import calc_trend_plan_money_metrics
return attach_trend_dca_levels(d)
d = attach_trend_dca_levels(d)
money = calc_trend_plan_money_metrics(d)
if money.get("money_rr") is not None:
d["money_rr"] = money["money_rr"]
d["planned_rr"] = money["money_rr"]
if money.get("risk_amount_u") is not None:
d["risk_amount_u"] = money["risk_amount_u"]
return d
def opened_at_str_to_ms(opened_at_str):
@@ -6801,12 +6813,15 @@ def execute_trend_pullback():
trading_day = get_trading_day(now)
opened_at = app_now_str()
opened_ms = _to_ms_with_fallback(None, opened_at)
from strategy_trend_lib import append_leg_fill_price_json
fills_json = append_leg_fill_price_json(None, fill1)
cur = conn.execute(
"""INSERT INTO trend_pullback_plans (
status,symbol,exchange_symbol,direction,leverage,stop_loss,initial_stop_loss,add_upper,take_profit,risk_percent,
snapshot_available_usdt,snapshot_at,plan_margin_capital,target_order_amount,first_order_amount,remainder_total,
dca_legs,per_leg_amount,grid_prices_json,leg_amounts_json,legs_done,first_order_done,last_mark_price,avg_entry_price,order_amount_open,opened_at,opened_at_ms,session_date,message
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
dca_legs,per_leg_amount,grid_prices_json,leg_amounts_json,legs_done,first_order_done,last_mark_price,avg_entry_price,order_amount_open,opened_at,opened_at_ms,session_date,message,leg_fill_prices_json
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
(
"active",
symbol,
@@ -6837,6 +6852,7 @@ def execute_trend_pullback():
opened_ms,
trading_day,
f"预览ID:{pid[:8]}",
fills_json,
),
)
new_plan_id = int(cur.lastrowid)