增加关键位人工输入
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from app.key_sl_tp import calc_planned_rr, normalize_sl_tp_mode, plan_key_sl_tp, stop_outside_pct_for_mode
|
||||
|
||||
|
||||
class TestKeySlTp(unittest.TestCase):
|
||||
def test_standard_long_plan(self):
|
||||
checks = {
|
||||
"confirm_close": 100.0,
|
||||
"breakout_high": 101.0,
|
||||
"breakout_low": 98.0,
|
||||
}
|
||||
plan = plan_key_sl_tp(
|
||||
"standard",
|
||||
"long",
|
||||
102.0,
|
||||
98.0,
|
||||
checks,
|
||||
outside_pct=0.3,
|
||||
trend_outside_pct=1.0,
|
||||
)
|
||||
self.assertIsNotNone(plan)
|
||||
e, sl, tp, h = plan # type: ignore[misc]
|
||||
self.assertEqual(e, 100.0)
|
||||
self.assertEqual(h, 4.0)
|
||||
self.assertEqual(tp, 104.0)
|
||||
self.assertAlmostEqual(sl, 98.0 * (1 - 0.003), places=6)
|
||||
|
||||
def test_trend_requires_manual_tp(self):
|
||||
checks = {
|
||||
"confirm_close": 100.0,
|
||||
"breakout_high": 101.0,
|
||||
"breakout_low": 98.0,
|
||||
}
|
||||
bad = plan_key_sl_tp(
|
||||
"trend_manual",
|
||||
"long",
|
||||
102.0,
|
||||
98.0,
|
||||
checks,
|
||||
outside_pct=0.3,
|
||||
trend_outside_pct=1.0,
|
||||
manual_take_profit=None,
|
||||
)
|
||||
self.assertIsNone(bad)
|
||||
ok = plan_key_sl_tp(
|
||||
"trend_manual",
|
||||
"long",
|
||||
102.0,
|
||||
98.0,
|
||||
checks,
|
||||
outside_pct=0.3,
|
||||
trend_outside_pct=1.0,
|
||||
manual_take_profit=110.0,
|
||||
)
|
||||
self.assertIsNotNone(ok)
|
||||
|
||||
def test_stop_pct_for_mode(self):
|
||||
self.assertEqual(stop_outside_pct_for_mode("standard"), 0.3)
|
||||
self.assertEqual(stop_outside_pct_for_mode("trend_manual"), 1.0)
|
||||
self.assertEqual(normalize_sl_tp_mode("box_1p5"), "standard")
|
||||
|
||||
def test_rr(self):
|
||||
rr = calc_planned_rr("long", 100.0, 98.0, 104.0)
|
||||
self.assertAlmostEqual(rr, 2.0, places=4)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user