5797d49d8a
统一 strategy、key_monitor、trade、hub 等共用库到 lib/ 子包,并补充 lib-structure 文档,便于四所与中控维护。 Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
781 B
Python
33 lines
781 B
Python
from lib.trade.manual_sltp_lib import (
|
|
MANUAL_FIXED_RR_DEFAULT,
|
|
calc_tp_from_fixed_rr,
|
|
parse_fixed_rr,
|
|
resolve_open_sltp_prices,
|
|
)
|
|
|
|
|
|
def test_calc_tp_from_fixed_rr_long():
|
|
tp = calc_tp_from_fixed_rr("long", 100.0, 95.0, 1.5)
|
|
assert tp == 107.5
|
|
|
|
|
|
def test_calc_tp_from_fixed_rr_short():
|
|
tp = calc_tp_from_fixed_rr("short", 100.0, 105.0, 1.5)
|
|
assert tp == 92.5
|
|
|
|
|
|
def test_resolve_open_fixed_rr_mode():
|
|
sl, tp = resolve_open_sltp_prices(
|
|
"long",
|
|
100.0,
|
|
"fixed_rr",
|
|
{"sl": "95", "fixed_rr": "1.5"},
|
|
)
|
|
assert sl == 95.0
|
|
assert tp == 107.5
|
|
|
|
|
|
def test_parse_fixed_rr_default():
|
|
assert parse_fixed_rr(None) == MANUAL_FIXED_RR_DEFAULT
|
|
assert parse_fixed_rr("2") == 2.0
|