From c5cf034ead6fb5a2bf687e07f81b0c620a9d2b30 Mon Sep 17 00:00:00 2001 From: dekun Date: Tue, 19 May 2026 10:16:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=90=E6=B3=A2=E5=B9=B3?= =?UTF-8?q?=E4=BB=93=E5=90=8E=E4=BA=A4=E6=98=93=E8=AE=B0=E5=BD=95=E8=AF=86?= =?UTF-8?q?=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crypto_monitor_binance/app.py | 5 ++--- crypto_monitor_gate/app.py | 8 ++++---- fib_key_monitor_lib.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crypto_monitor_binance/app.py b/crypto_monitor_binance/app.py index 8e50f0a..0275dbe 100644 --- a/crypto_monitor_binance/app.py +++ b/crypto_monitor_binance/app.py @@ -40,6 +40,7 @@ from fib_key_monitor_lib import ( fib_invalidate_by_mark, fib_ratio_from_type, is_fib_key_monitor_type, + key_signal_type_for_trade_record, stored_key_signal_type, ) @@ -2026,9 +2027,7 @@ def insert_trade_record( close_ts = closed_at or app_now_str() open_ts_ms = _to_ms_with_fallback(opened_at_ms, open_ts) close_ts_ms = _to_ms_with_fallback(closed_at_ms, close_ts) - kst = (key_signal_type or "").strip() - if kst not in KEY_MONITOR_AUTO_TYPES: - kst = None + kst = key_signal_type_for_trade_record(key_signal_type, KEY_MONITOR_AUTO_TYPES) conn.execute( "INSERT INTO trade_records (symbol,monitor_type,key_signal_type,direction,trigger_price,stop_loss,initial_stop_loss,take_profit,margin_capital,leverage,pnl_amount,hold_seconds,trade_style,risk_amount,planned_rr,actual_rr,hold_minutes,opened_at,opened_at_ms,closed_at,closed_at_ms,result,miss_reason,exchange_trade_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", ( diff --git a/crypto_monitor_gate/app.py b/crypto_monitor_gate/app.py index e260b3b..54f7c81 100644 --- a/crypto_monitor_gate/app.py +++ b/crypto_monitor_gate/app.py @@ -40,6 +40,7 @@ from fib_key_monitor_lib import ( fib_invalidate_by_mark, fib_ratio_from_type, is_fib_key_monitor_type, + key_signal_type_for_trade_record, stored_key_signal_type, ) @@ -2004,9 +2005,7 @@ def insert_trade_record( close_ts = closed_at or app_now_str() open_ts_ms = _to_ms_with_fallback(opened_at_ms, open_ts) close_ts_ms = _to_ms_with_fallback(closed_at_ms, close_ts) - kst = (key_signal_type or "").strip() - if kst not in KEY_MONITOR_AUTO_TYPES: - kst = None + kst = key_signal_type_for_trade_record(key_signal_type, KEY_MONITOR_AUTO_TYPES) conn.execute( "INSERT INTO trade_records (symbol,monitor_type,key_signal_type,direction,trigger_price,stop_loss,initial_stop_loss,take_profit,margin_capital,leverage,pnl_amount,hold_seconds,trade_style,risk_amount,planned_rr,actual_rr,hold_minutes,opened_at,opened_at_ms,closed_at,closed_at_ms,result,miss_reason,exchange_trade_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", ( @@ -6740,7 +6739,8 @@ def del_order(id): insert_trade_record( conn, symbol=row["symbol"], - monitor_type="下单监控", + monitor_type=order_row_monitor_type(row), + key_signal_type=order_row_key_signal_type(row), direction=row["direction"], trigger_price=row["trigger_price"], stop_loss=row["stop_loss"], diff --git a/fib_key_monitor_lib.py b/fib_key_monitor_lib.py index ed09f61..d8176ec 100644 --- a/fib_key_monitor_lib.py +++ b/fib_key_monitor_lib.py @@ -48,6 +48,16 @@ def stored_key_signal_type(monitor_type): return None +def key_signal_type_for_trade_record(key_signal_type, box_auto_types): + """平仓写入 trade_records 时保留箱体/收敛/斐波来源。""" + kst = (key_signal_type or "").strip() + if kst in FIB_KEY_MONITOR_TYPES: + return kst + if box_auto_types and kst in box_auto_types: + return kst + return None + + def fib_invalidate_by_mark(direction, mark_price, upper, lower): """先触达止盈侧(标记价)则失效。多:mark>=H;空:mark<=L。""" try: