diff --git a/crypto_monitor_binance/app.py b/crypto_monitor_binance/app.py index d882746..356a271 100644 --- a/crypto_monitor_binance/app.py +++ b/crypto_monitor_binance/app.py @@ -220,7 +220,11 @@ from lib.common.history_window_lib import ( utc_window_to_bj_sql_strings, utc_window_to_utc_sql_strings, ) -from lib.trade.trade_result_lib import count_winning_trades, normalize_result_with_pnl +from lib.trade.trade_result_lib import ( + count_winning_trades, + filter_trade_records_excluding_miss, + normalize_result_with_pnl, +) from lib.trade.trade_exchange_stats_lib import ( attach_exchange_stats_to_trade, filter_position_lifecycle_fills, @@ -7119,27 +7123,20 @@ def render_main_page(page="trade", embed_mode=None): f"SELECT * FROM trade_records WHERE {tr_ts} >= ? AND {tr_ts} <= ? ORDER BY id DESC LIMIT 1000", (start_bj, end_bj), ).fetchall() - records = [to_effective_trade_dict(r) for r in raw_records] - total = len(records) - miss_count = sum(1 for r in records if (r.get("effective_result") or "") == "错过") - win = count_winning_trades(records) - occupied_miss_total = sum( - 1 - for r in records - if (r.get("effective_result") or "") == "错过" - and ("持仓占用" in str(r.get("effective_miss_reason") or "")) + records = filter_trade_records_excluding_miss( + [to_effective_trade_dict(r) for r in raw_records] ) + total = len(records) + win = count_winning_trades(records) rate = round(win / total * 100, 2) if total else 0 elif plan.records_summary: summary = trade_records_summary(conn, start_bj, end_bj, tr_ts) records = summary["records"] total = summary["total"] - miss_count = summary["miss_count"] rate = summary["rate"] - occupied_miss_total = summary["occupied_miss_total"] else: records = [] - total = miss_count = rate = occupied_miss_total = 0 + total = rate = 0 active_count = len(order_list) from lib.strategy.strategy_trade_labels import count_position_limit_active_monitors @@ -7196,7 +7193,6 @@ def render_main_page(page="trade", embed_mode=None): orphan_live_positions=orphan_live_positions, record=records, total=total, - miss_count=miss_count, rate=rate, trading_day=trading_day, funding_usdt=funding_usdt, @@ -7239,7 +7235,6 @@ def render_main_page(page="trade", embed_mode=None): ), breakeven_rr_trigger=BREAKEVEN_RR_TRIGGER, breakeven_offset_pct=BREAKEVEN_OFFSET_PCT, - occupied_miss_total=occupied_miss_total, price_fmt=format_price_for_symbol, funds_fmt=format_funds_u, entry_reason_options=list(ENTRY_REASON_OPTIONS), @@ -8358,27 +8353,6 @@ def add_order(): return redirect("/trade") ok, reason = precheck_risk(conn, symbol, direction) if not ok: - if "已达最大持仓数" in reason: - try: - tp_raw = parse_positive_float(d.get("tp")) - sl_raw = parse_positive_float(d.get("sl")) - tgt_raw = parse_positive_float(d.get("tgt")) - except Exception: - tp_raw = sl_raw = tgt_raw = None - insert_trade_record( - conn, - symbol=symbol, - monitor_type="下单监控", - direction=direction if direction in ("long", "short") else "long", - trigger_price=tp_raw or 0, - stop_loss=sl_raw or 0, - take_profit=tgt_raw or 0, - result="错过", - miss_reason=f"持仓占用:{reason}", - opened_at=app_now_str(), - closed_at=app_now_str(), - ) - conn.commit() conn.close() flash(f"风控拒绝下单:{reason}") return redirect("/trade") @@ -9091,30 +9065,6 @@ def del_order(id): conn.close() return redirect("/") -@app.route("/add_miss", methods=["POST"]) -@login_required -def add_miss(): - d = request.form - direction = d.get("direction", "long") - conn = get_db() - insert_trade_record( - conn, - symbol=d["symbol"], - monitor_type=d["type"], - direction=direction, - trigger_price=d["tp"], - stop_loss=d["sl"], - take_profit=d["tgt"], - result="错过", - miss_reason=d["reason"], - opened_at=app_now_str(), - closed_at=app_now_str(), - ) - conn.commit() - conn.close() - flash("已记录错过机会") - return _redirect_records() - @app.route("/add_journal", methods=["POST"]) @login_required diff --git a/crypto_monitor_binance/templates/index.html b/crypto_monitor_binance/templates/index.html index 4a547bc..eaca758 100644 --- a/crypto_monitor_binance/templates/index.html +++ b/crypto_monitor_binance/templates/index.html @@ -334,7 +334,6 @@