Files
crypto_monitor/tests/test_entry_model_lib.py
T
dekun 4904a86e03 fix: hide hub close/entrust controls for intraday discipline profile
Expose intraday_discipline via hub meta and block manual close/tpsl APIs; Gate instance card no longer shows 全平/平仓/委托.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 02:26:22 +08:00

86 lines
3.2 KiB
Python

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,
hub_meta_entry_context,
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_hub_meta_intraday(self):
policy = load_trade_policy(
{
"TRADE_SYMBOL_RESTRICT_ENABLED": "true",
"TRADE_SYMBOL_WHITELIST": "BTC,ETH",
}
)
ctx = hub_meta_entry_context(policy)
self.assertTrue(ctx["intraday_discipline"])
self.assertEqual(ctx["order_entry_profile"], "intraday")
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()