51b8bb8f8a
Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
from app.strategy.signal import decide
|
|
from app.strategy.exits import check_exits
|
|
from app.sim.pricing import option_fill, perp_fill
|
|
from app.strategy.clock import can_open_new, window_key
|
|
from datetime import datetime
|
|
from zoneinfo import ZoneInfo
|
|
|
|
_SH = ZoneInfo("Asia/Shanghai")
|
|
|
|
|
|
def test_signal_buy_call_short_perp() -> None:
|
|
s = decide(20.0, 15.0)
|
|
assert s is not None
|
|
assert s.option_side == "call"
|
|
assert s.perp_side == "short"
|
|
|
|
|
|
def test_signal_buy_put_long_perp() -> None:
|
|
s = decide(10.0, 16.0)
|
|
assert s is not None
|
|
assert s.option_side == "put"
|
|
assert s.perp_side == "long"
|
|
|
|
|
|
def test_signal_equal() -> None:
|
|
assert decide(10.0, 10.0) is None
|
|
|
|
|
|
def test_exit_premium_and_move() -> None:
|
|
assert check_exits(
|
|
perp_upl=50, initial_premium=40, move_points=1, exit_move_points=30
|
|
).reason == "premium_cover"
|
|
assert check_exits(
|
|
perp_upl=1, initial_premium=40, move_points=30, exit_move_points=30
|
|
).reason == "move_points"
|
|
|
|
|
|
def test_perp_pricing() -> None:
|
|
r = perp_fill(side="long", action="open", bid=100, ask=101, qty_eth=1, fee_rate=0.001)
|
|
assert abs(r.fill_px - 101 * 1.001) < 1e-9
|
|
|
|
|
|
def test_option_open_close_pricing() -> None:
|
|
o = option_fill(action="open", bid=10, ask=12, qty_eth=2, fee_rate=0.001)
|
|
assert o.fill_px > 12
|
|
c = option_fill(action="close", bid=10, ask=12, qty_eth=2, fee_rate=0.001)
|
|
assert c.fill_px < 10
|
|
|
|
|
|
def test_window() -> None:
|
|
# 17:00 can open, window key today
|
|
n = datetime(2026, 7, 24, 17, 0, tzinfo=_SH)
|
|
assert can_open_new(n) is True
|
|
assert window_key(n) == "20260724"
|
|
# 10:00 cannot open
|
|
n2 = datetime(2026, 7, 24, 10, 0, tzinfo=_SH)
|
|
assert can_open_new(n2) is False
|
|
# 07:00 still previous window, can open
|
|
n3 = datetime(2026, 7, 24, 7, 0, tzinfo=_SH)
|
|
assert can_open_new(n3) is True
|
|
assert window_key(n3) == "20260723"
|