Files
crypto_monitor_user/tests/test_journal_form_lib.py
T
dekun 53863559f4 Initialize crypto_monitor_user (user edition) from monitor codebase.
Retarget git remote, install path, and deploy docs from crypto_monitor to crypto_monitor_user.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 16:18:13 +08:00

72 lines
2.9 KiB
Python

"""journal_form_lib / strategy_trade_labels 下单类型与开仓类型拆分."""
from __future__ import annotations
import unittest
from lib.instance.journal_form_lib import (
journal_entry_reason_valid,
normalize_journal_direction,
normalize_journal_entry_reason,
)
from lib.strategy.strategy_trade_labels import (
JOURNAL_ORDER_TYPE_OPTIONS,
normalize_journal_order_type,
order_type_from_monitor_type,
)
from lib.trade.entry_model_lib import build_journal_entry_reason_options
class JournalFormLibTests(unittest.TestCase):
def test_journal_entry_reason_excludes_legacy_style_and_strategy(self):
opts = build_journal_entry_reason_options()
self.assertIn("反转/启动A", opts)
self.assertNotIn("趋势单", opts)
self.assertNotIn("波段单", opts)
self.assertNotIn("趋势回调", opts)
self.assertNotIn("顺势加仓", opts)
def test_normalize_journal_entry_reason_rejects_legacy_for_new_submit(self):
opts = build_journal_entry_reason_options()
self.assertEqual(
normalize_journal_entry_reason("趋势单", opts, allow_legacy=False),
"",
)
self.assertEqual(
normalize_journal_entry_reason("趋势回调", opts, allow_legacy=False),
"",
)
def test_normalize_journal_entry_reason_accepts_legacy_when_allowed(self):
opts = build_journal_entry_reason_options()
self.assertEqual(
normalize_journal_entry_reason("趋势单", opts, allow_legacy=True),
"趋势单",
)
def test_order_type_from_monitor_type(self):
self.assertEqual(order_type_from_monitor_type("下单监控"), "下单监控")
self.assertEqual(order_type_from_monitor_type("关键位监控"), "关键位监控")
self.assertEqual(order_type_from_monitor_type("趋势回调"), "趋势回调")
self.assertEqual(order_type_from_monitor_type("顺势加仓"), "顺势加仓")
def test_normalize_journal_order_type(self):
self.assertEqual(normalize_journal_order_type("顺势加仓"), "顺势加仓")
self.assertEqual(normalize_journal_order_type(""), "")
self.assertEqual(len(JOURNAL_ORDER_TYPE_OPTIONS), 4)
def test_journal_entry_reason_valid(self):
opts = build_journal_entry_reason_options()
self.assertTrue(journal_entry_reason_valid("顺势/大分歧A", opts))
self.assertFalse(journal_entry_reason_valid("趋势单", opts))
def test_normalize_journal_direction(self):
self.assertEqual(normalize_journal_direction("short"), "short")
self.assertEqual(normalize_journal_direction("做空"), "short")
self.assertEqual(normalize_journal_direction("long"), "long")
self.assertEqual(normalize_journal_direction("做多"), "long")
self.assertEqual(normalize_journal_direction(""), "")
if __name__ == "__main__":
unittest.main()