feat: 趋势户开仓类型大分歧A/B/小分歧,自动联动趋势波段与复盘
下单监控增加 entry_model 下拉;平仓写入短标签并预填复盘。Binance/OKX 用趋势 profile,Gate 日内仍用手选 trade_style。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import unittest
|
||||
|
||||
from lib.trade.entry_model_lib import (
|
||||
ENTRY_MODEL_BIG_DIV_A,
|
||||
ENTRY_MODEL_BIG_DIV_B,
|
||||
ENTRY_MODEL_SMALL_DIV,
|
||||
build_trend_div_entry_reason_options,
|
||||
entry_model_label,
|
||||
is_intraday_trading_profile,
|
||||
parse_manual_order_style_fields,
|
||||
resolve_trade_record_entry_reason,
|
||||
trade_style_for_entry_model,
|
||||
trend_manual_entry_reason_count,
|
||||
)
|
||||
from lib.trade.trade_policy_lib import TradePolicy, load_trade_policy
|
||||
|
||||
|
||||
class TestEntryModelLib(unittest.TestCase):
|
||||
def test_intraday_profile_btc_eth_whitelist(self):
|
||||
policy = load_trade_policy(
|
||||
{
|
||||
"TRADE_SYMBOL_RESTRICT_ENABLED": "true",
|
||||
"TRADE_SYMBOL_WHITELIST": "BTC,ETH",
|
||||
}
|
||||
)
|
||||
self.assertTrue(is_intraday_trading_profile(policy))
|
||||
self.assertEqual(trend_manual_entry_reason_count(policy), 5)
|
||||
|
||||
def test_trend_div_profile_alt(self):
|
||||
policy = load_trade_policy(
|
||||
{
|
||||
"TRADE_SYMBOL_RESTRICT_ENABLED": "false",
|
||||
"TRADE_SYMBOL_WHITELIST": "BTC,ETH",
|
||||
}
|
||||
)
|
||||
self.assertFalse(is_intraday_trading_profile(policy))
|
||||
self.assertEqual(trend_manual_entry_reason_count(policy), 3)
|
||||
|
||||
def test_entry_model_maps_trade_style(self):
|
||||
self.assertEqual(trade_style_for_entry_model(ENTRY_MODEL_BIG_DIV_A), "trend")
|
||||
self.assertEqual(trade_style_for_entry_model(ENTRY_MODEL_SMALL_DIV), "swing")
|
||||
self.assertEqual(entry_model_label(ENTRY_MODEL_BIG_DIV_A), "大分歧A")
|
||||
|
||||
def test_parse_trend_div_requires_entry_model(self):
|
||||
policy = TradePolicy(False, "both", False, ())
|
||||
style, code, err = parse_manual_order_style_fields(policy, {})
|
||||
self.assertTrue(err)
|
||||
self.assertEqual(code, None)
|
||||
|
||||
style, code, err = parse_manual_order_style_fields(
|
||||
policy, {"entry_model": ENTRY_MODEL_SMALL_DIV}
|
||||
)
|
||||
self.assertIsNone(err)
|
||||
self.assertEqual(code, ENTRY_MODEL_SMALL_DIV)
|
||||
self.assertEqual(style, "swing")
|
||||
|
||||
def test_parse_intraday_uses_trade_style(self):
|
||||
policy = TradePolicy(False, "both", True, ("BTC", "ETH"))
|
||||
style, code, err = parse_manual_order_style_fields(policy, {"trade_style": "swing"})
|
||||
self.assertIsNone(err)
|
||||
self.assertIsNone(code)
|
||||
self.assertEqual(style, "swing")
|
||||
|
||||
def test_resolve_entry_reason_from_model(self):
|
||||
er = resolve_trade_record_entry_reason(entry_model=ENTRY_MODEL_BIG_DIV_B)
|
||||
self.assertEqual(er, "大分歧B")
|
||||
|
||||
def test_build_trend_div_journal_options(self):
|
||||
opts = build_trend_div_entry_reason_options(("趋势回调",))
|
||||
self.assertEqual(opts[:3], ("大分歧A", "大分歧B", "小分歧"))
|
||||
self.assertIn("趋势回调", opts)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user