feat: 关键位回调/突破触价开仓拆分与穿越触发

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-29 10:49:43 +08:00
parent e51d7824a7
commit 5b3448b52b
20 changed files with 662 additions and 172 deletions
+50 -11
View File
@@ -1,11 +1,17 @@
"""触价开仓关键位监控单元测试。"""
"""触价开仓(回调/突破)关键位监控单元测试。"""
from trigger_entry_key_monitor_lib import (
TRIGGER_ENTRY_MONITOR_TYPE,
BREAKOUT_TRIGGER_ENTRY_MONITOR_TYPE,
CALLBACK_TRIGGER_ENTRY_MONITOR_TYPE,
LEGACY_TRIGGER_ENTRY_MONITOR_TYPE,
TRIGGER_ENTRY_MONITOR_TYPES,
TRIGGER_ENTRY_VALIDITY_HOURS,
breakout_trigger_entry_crossed,
check_trigger_entry_intent_limit,
is_breakout_trigger_entry_key_monitor_type,
is_trigger_entry_key_monitor_type,
trigger_entry_invalidate_by_tp,
trigger_entry_invalidate,
trigger_entry_reached,
trigger_should_fire,
validate_trigger_entry_geometry,
)
@@ -14,7 +20,7 @@ class _FakeConn:
def execute(self, sql, params=()):
class R:
def fetchone(self_inner):
return (params[1] == "2026-06-07" and 2,) # 2 pending
return (2,)
return R()
@@ -24,14 +30,43 @@ def test_trigger_entry_reached_long():
assert trigger_entry_reached("long", 2051.0, 2050.0) is False
def test_trigger_entry_invalidate_long():
assert trigger_entry_invalidate_by_tp("long", 2100.0, 2100.0) is True
assert trigger_entry_invalidate_by_tp("long", 2099.0, 2100.0) is False
def test_breakout_cross_long_up():
assert breakout_trigger_entry_crossed("long", 99.0, 100.5, 100.0) is True
assert breakout_trigger_entry_crossed("long", None, 101.0, 100.0) is True
assert breakout_trigger_entry_crossed("long", 100.0, 100.0, 100.0) is False
def test_validate_geometry_long():
def test_breakout_cross_short_down():
assert breakout_trigger_entry_crossed("short", 101.0, 99.5, 100.0) is True
assert breakout_trigger_entry_crossed("short", None, 99.0, 100.0) is True
def test_trigger_should_fire_modes():
assert trigger_should_fire(CALLBACK_TRIGGER_ENTRY_MONITOR_TYPE, "long", 2049.0, 2050.0) is True
assert trigger_should_fire(BREAKOUT_TRIGGER_ENTRY_MONITOR_TYPE, "long", 100.5, 100.0, 99.0) is True
def test_validate_geometry_callback_long():
assert validate_trigger_entry_geometry("long", 2050, 2000, 2100, 2090) is None
assert "止损" in (validate_trigger_entry_geometry("long", 2050, 2100, 2000) or "")
def test_validate_geometry_breakout_short_requires_mark_above_entry():
assert (
validate_trigger_entry_geometry(
"short", 551, 568, 540, 560, monitor_type=BREAKOUT_TRIGGER_ENTRY_MONITOR_TYPE
)
is None
)
err = validate_trigger_entry_geometry(
"short", 551, 568, 540, 550, monitor_type=BREAKOUT_TRIGGER_ENTRY_MONITOR_TYPE
)
assert err is not None
assert "高于入场价" in err
def test_invalidate_breakout_sl_side():
assert trigger_entry_invalidate(BREAKOUT_TRIGGER_ENTRY_MONITOR_TYPE, "long", 96, 97, 110) == "sl"
assert trigger_entry_invalidate(CALLBACK_TRIGGER_ENTRY_MONITOR_TYPE, "long", 96, 97, 110) is None
def test_intent_limit():
@@ -40,6 +75,10 @@ def test_intent_limit():
assert "意图" in msg
def test_type_name():
assert is_trigger_entry_key_monitor_type(TRIGGER_ENTRY_MONITOR_TYPE)
def test_type_names():
assert is_trigger_entry_key_monitor_type(CALLBACK_TRIGGER_ENTRY_MONITOR_TYPE)
assert is_trigger_entry_key_monitor_type(BREAKOUT_TRIGGER_ENTRY_MONITOR_TYPE)
assert is_trigger_entry_key_monitor_type(LEGACY_TRIGGER_ENTRY_MONITOR_TYPE)
assert is_breakout_trigger_entry_key_monitor_type(BREAKOUT_TRIGGER_ENTRY_MONITOR_TYPE)
assert CALLBACK_TRIGGER_ENTRY_MONITOR_TYPE in TRIGGER_ENTRY_MONITOR_TYPES
assert TRIGGER_ENTRY_VALIDITY_HOURS == 24