fix: 修正突破加仓当前价与突破价的几何校验
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -266,13 +266,13 @@ def validate_roll_geometry(
|
|||||||
if direction == "long":
|
if direction == "long":
|
||||||
if sl >= bp:
|
if sl >= bp:
|
||||||
return "做多:止损须低于突破价"
|
return "做多:止损须低于突破价"
|
||||||
if mark_price is not None and float(mark_price) <= bp:
|
if mark_price is not None and float(mark_price) >= bp:
|
||||||
return "做多:当前价须高于突破价(等待向上突破)"
|
return "做多:当前价须低于突破价(等待向上突破)"
|
||||||
else:
|
else:
|
||||||
if sl <= bp:
|
if sl <= bp:
|
||||||
return "做空:止损须高于突破价"
|
return "做空:止损须高于突破价"
|
||||||
if mark_price is not None and float(mark_price) >= bp:
|
if mark_price is not None and float(mark_price) <= bp:
|
||||||
return "做空:当前价须低于突破价(等待向下突破)"
|
return "做空:当前价须高于突破价(等待向下跌破)"
|
||||||
else:
|
else:
|
||||||
return "加仓方式无效"
|
return "加仓方式无效"
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from strategy_roll_lib import (
|
|||||||
roll_fib_invalidate,
|
roll_fib_invalidate,
|
||||||
roll_fib_trigger_crossed,
|
roll_fib_trigger_crossed,
|
||||||
solve_add_amount_for_total_risk,
|
solve_add_amount_for_total_risk,
|
||||||
|
validate_roll_geometry,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -64,7 +65,48 @@ def test_preview_breakout_mode_label():
|
|||||||
breakthrough_price=3100.0,
|
breakthrough_price=3100.0,
|
||||||
risk_percent=10.0,
|
risk_percent=10.0,
|
||||||
capital_base_usdt=1000.0,
|
capital_base_usdt=1000.0,
|
||||||
add_price=3150.0,
|
add_price=3050.0,
|
||||||
)
|
)
|
||||||
assert err is None
|
assert err is None
|
||||||
assert preview["add_mode_label"] == "突破加仓"
|
assert preview["add_mode_label"] == "突破加仓"
|
||||||
|
|
||||||
|
|
||||||
|
def test_breakout_geometry_short_mark_above_breakout():
|
||||||
|
err = validate_roll_geometry(
|
||||||
|
"short",
|
||||||
|
"breakout",
|
||||||
|
new_stop_loss=568.0,
|
||||||
|
breakthrough_price=551.0,
|
||||||
|
entry_existing=560.0,
|
||||||
|
initial_take_profit=540.0,
|
||||||
|
mark_price=560.0,
|
||||||
|
)
|
||||||
|
assert err is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_breakout_geometry_short_rejects_mark_at_or_below_breakout():
|
||||||
|
err = validate_roll_geometry(
|
||||||
|
"short",
|
||||||
|
"breakout",
|
||||||
|
new_stop_loss=568.0,
|
||||||
|
breakthrough_price=551.0,
|
||||||
|
entry_existing=560.0,
|
||||||
|
initial_take_profit=540.0,
|
||||||
|
mark_price=551.0,
|
||||||
|
)
|
||||||
|
assert err is not None
|
||||||
|
assert "高于突破价" in err
|
||||||
|
|
||||||
|
|
||||||
|
def test_breakout_geometry_long_rejects_mark_at_or_above_breakout():
|
||||||
|
err = validate_roll_geometry(
|
||||||
|
"long",
|
||||||
|
"breakout",
|
||||||
|
new_stop_loss=2980.0,
|
||||||
|
breakthrough_price=3100.0,
|
||||||
|
entry_existing=3000.0,
|
||||||
|
initial_take_profit=3500.0,
|
||||||
|
mark_price=3100.0,
|
||||||
|
)
|
||||||
|
assert err is not None
|
||||||
|
assert "低于突破价" in err
|
||||||
|
|||||||
Reference in New Issue
Block a user