Files
crypto_monitor/tests/test_trade_result_lib.py
T

48 lines
1.5 KiB
Python

from lib.trade.trade_result_lib import (
classify_exit_by_levels,
normalize_result_with_pnl,
normalize_display_result,
is_winning_pnl,
)
def test_classify_short_tp_with_slippage_past_tight_band():
# Gate BTC 空单:计划止盈 62600,实际成交约 62738(条件单滑点),旧窄带会误判为外部平仓
assert (
classify_exit_by_levels("short", 64256.2, 65400, 62600, 62738.0) == "止盈"
)
def test_classify_long_sl_and_tp_basic():
assert classify_exit_by_levels("long", 100, 95, 110, 110.05) == "止盈"
assert classify_exit_by_levels("long", 100, 95, 110, 94.9) == "止损"
def test_stop_loss_with_profit_becomes_trailing_tp():
assert normalize_result_with_pnl("止损", 4.33) == "移动止盈"
def test_manual_close_unchanged_even_with_profit():
assert normalize_result_with_pnl("手动平仓", 10) == "手动平仓"
def test_stop_loss_with_loss_unchanged():
assert normalize_result_with_pnl("止损", -2.5) == "止损"
def test_take_profit_unchanged():
assert normalize_result_with_pnl("止盈", 5) == "止盈"
def test_external_close_becomes_manual_close():
assert normalize_display_result("外部平仓") == "手动平仓"
assert normalize_result_with_pnl("外部平仓", 2.5) == "手动平仓"
assert normalize_result_with_pnl("外部平仓(自动同步)", -1) == "手动平仓"
def test_winning_pnl_positive_only():
assert is_winning_pnl(2.96) is True
assert is_winning_pnl(0) is False
assert is_winning_pnl(-1.05) is False
assert is_winning_pnl(None) is False