Add period selector and crypto-style trend plan preview table.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+30
-5
@@ -67,7 +67,14 @@ from risk.account_risk_lib import (
|
||||
from strategy.strategy_db import init_strategy_tables
|
||||
from strategy.strategy_roll_lib import preview_roll
|
||||
from strategy.strategy_snapshot_lib import list_snapshots, save_snapshot
|
||||
from strategy.strategy_trend_lib import compute_trend_plan_futures, trend_dca_level_reached
|
||||
from strategy.strategy_trend_lib import (
|
||||
compute_trend_plan_futures,
|
||||
enrich_trend_plan_preview,
|
||||
normalize_trend_period,
|
||||
trend_dca_level_reached,
|
||||
trend_period_label,
|
||||
trend_strategy_periods,
|
||||
)
|
||||
from strategy.strategy_snapshot_lib import STRATEGY_ROLL, STRATEGY_TREND
|
||||
from symbols import ths_to_codes, resolve_main_contract, PRODUCTS, PRODUCT_CATEGORIES, position_symbol_meta
|
||||
from trading_context import (
|
||||
@@ -1998,15 +2005,19 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
roll_groups = conn.execute(
|
||||
"SELECT * FROM roll_groups WHERE status='active' ORDER BY id DESC"
|
||||
).fetchall()
|
||||
active_trend_row = dict(active_trend) if active_trend else None
|
||||
if active_trend_row:
|
||||
active_trend_row["period_label"] = trend_period_label(active_trend_row.get("period") or "15m")
|
||||
conn.close()
|
||||
return render_template(
|
||||
"strategy.html",
|
||||
capital=capital,
|
||||
risk_percent=get_risk_percent(get_setting),
|
||||
sizing_mode=get_sizing_mode(get_setting),
|
||||
active_trend=dict(active_trend) if active_trend else None,
|
||||
active_trend=active_trend_row,
|
||||
monitors=[dict(m) for m in monitors],
|
||||
roll_groups=[dict(g) for g in roll_groups],
|
||||
trend_periods=trend_strategy_periods(),
|
||||
)
|
||||
|
||||
@app.route("/strategy/records")
|
||||
@@ -2471,6 +2482,13 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
)
|
||||
if err:
|
||||
return jsonify({"ok": False, "error": err}), 400
|
||||
period = normalize_trend_period(d.get("period"))
|
||||
sym_name = (d.get("symbol_name") or "").strip()
|
||||
if not sym_name and codes:
|
||||
sym_name = codes.get("name") or sym
|
||||
plan = enrich_trend_plan_preview(
|
||||
plan, symbol=sym, symbol_name=sym_name, period=period,
|
||||
)
|
||||
return jsonify({"ok": True, "plan": plan})
|
||||
|
||||
@app.route("/api/strategy/trend/execute", methods=["POST"])
|
||||
@@ -2500,6 +2518,13 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
if perr:
|
||||
conn.close()
|
||||
return jsonify({"ok": False, "error": perr}), 400
|
||||
period = normalize_trend_period(d.get("period"))
|
||||
sym_name = (d.get("symbol_name") or "").strip()
|
||||
if not sym_name and codes:
|
||||
sym_name = codes.get("name") or sym
|
||||
plan = enrich_trend_plan_preview(
|
||||
plan, symbol=sym, symbol_name=sym_name, period=period,
|
||||
)
|
||||
mode = get_trading_mode(get_setting)
|
||||
try:
|
||||
execute_order(
|
||||
@@ -2515,15 +2540,15 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
status, symbol, symbol_name, direction, stop_loss, add_upper, take_profit,
|
||||
risk_percent, capital_snapshot, plan_margin, target_lots, first_lots, remainder_lots,
|
||||
dca_legs, leg_amounts_json, grid_prices_json, first_order_done, avg_entry_price,
|
||||
lots_open, opened_at
|
||||
lots_open, opened_at, period
|
||||
) VALUES ('active',?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,1,?,?,?,?)""",
|
||||
(
|
||||
sym, codes.get("name", sym) if codes else sym, plan["direction"],
|
||||
sym, sym_name or (codes.get("name", sym) if codes else sym), plan["direction"],
|
||||
plan["stop_loss"], plan["add_upper"], plan["take_profit"],
|
||||
plan["risk_percent"], plan["capital_snapshot"], plan["plan_margin"],
|
||||
plan["target_lots"], plan["first_lots"], plan["remainder_lots"],
|
||||
plan["dca_legs"], plan["leg_amounts_json"], plan["grid_prices_json"],
|
||||
price, plan["first_lots"], now,
|
||||
price, plan["first_lots"], now, plan["period"],
|
||||
),
|
||||
)
|
||||
plan_id = cur.lastrowid
|
||||
|
||||
Reference in New Issue
Block a user