91 lines
2.5 KiB
Python
91 lines
2.5 KiB
Python
|
|
"""
|
||
|
|
数据模型测试
|
||
|
|
"""
|
||
|
|
|
||
|
|
from decimal import Decimal
|
||
|
|
|
||
|
|
|
||
|
|
class TestOrderModel:
|
||
|
|
"""订单模型测试"""
|
||
|
|
|
||
|
|
def test_order_side_enum(self) -> None:
|
||
|
|
"""测试订单方向枚举"""
|
||
|
|
from src.core.models.order import OrderSide
|
||
|
|
|
||
|
|
assert OrderSide.BUY.value == "BUY"
|
||
|
|
assert OrderSide.SELL.value == "SELL"
|
||
|
|
|
||
|
|
def test_order_status_enum(self) -> None:
|
||
|
|
"""测试订单状态枚举"""
|
||
|
|
from src.core.models.order import OrderStatus
|
||
|
|
|
||
|
|
assert OrderStatus.PENDING.value == "PENDING"
|
||
|
|
assert OrderStatus.FILLED.value == "FILLED"
|
||
|
|
assert OrderStatus.CANCELLED.value == "CANCELLED"
|
||
|
|
|
||
|
|
def test_order_create_schema(self) -> None:
|
||
|
|
"""测试订单创建 Schema"""
|
||
|
|
from src.core.models.order import OrderCreate, OrderSide
|
||
|
|
|
||
|
|
order = OrderCreate(
|
||
|
|
pairing_id="pairing_001",
|
||
|
|
symbol="000001.SZ",
|
||
|
|
side=OrderSide.BUY,
|
||
|
|
quantity=100,
|
||
|
|
price=Decimal("10.50"),
|
||
|
|
)
|
||
|
|
|
||
|
|
assert order.symbol == "000001.SZ"
|
||
|
|
assert order.quantity == 100
|
||
|
|
assert order.price == Decimal("10.50")
|
||
|
|
|
||
|
|
|
||
|
|
class TestPositionModel:
|
||
|
|
"""持仓模型测试"""
|
||
|
|
|
||
|
|
def test_position_model(self) -> None:
|
||
|
|
"""测试持仓模型"""
|
||
|
|
from src.core.models.position import Position
|
||
|
|
|
||
|
|
position = Position(
|
||
|
|
id="pos_001",
|
||
|
|
pairing_id="pairing_001",
|
||
|
|
strategy_id="grid_001",
|
||
|
|
symbol="000001.SZ",
|
||
|
|
quantity=1000,
|
||
|
|
available=1000,
|
||
|
|
avg_cost=Decimal("10.00"),
|
||
|
|
market_value=None,
|
||
|
|
unrealized_pnl=None,
|
||
|
|
)
|
||
|
|
|
||
|
|
assert position.symbol == "000001.SZ"
|
||
|
|
assert position.quantity == 1000
|
||
|
|
|
||
|
|
|
||
|
|
class TestSignalModel:
|
||
|
|
"""信号模型测试"""
|
||
|
|
|
||
|
|
def test_signal_side_enum(self) -> None:
|
||
|
|
"""测试信号方向枚举"""
|
||
|
|
from src.core.models.signal import SignalSide
|
||
|
|
|
||
|
|
assert SignalSide.BUY.value == "buy"
|
||
|
|
assert SignalSide.SELL.value == "sell"
|
||
|
|
|
||
|
|
def test_signal_create_schema(self) -> None:
|
||
|
|
"""测试信号创建 Schema"""
|
||
|
|
from src.core.models.signal import SignalCreate, SignalSide
|
||
|
|
|
||
|
|
signal = SignalCreate(
|
||
|
|
pairing_id="pairing_001",
|
||
|
|
symbol="000001.SZ",
|
||
|
|
side=SignalSide.BUY,
|
||
|
|
price=10.50,
|
||
|
|
quantity=100,
|
||
|
|
reason="价格触及网格买入点",
|
||
|
|
)
|
||
|
|
|
||
|
|
assert signal.pairing_id == "pairing_001"
|
||
|
|
assert signal.side == SignalSide.BUY
|