| from datetime import datetime |
| from enum import Enum |
|
|
| from pydantic import BaseModel, Field |
|
|
|
|
| class OrderSide(str, Enum): |
| BUY = "BUY" |
| SELL = "SELL" |
|
|
|
|
| class OrderType(str, Enum): |
| MARKET = "MARKET" |
| LIMIT = "LIMIT" |
| STOP = "STOP" |
|
|
|
|
| class OrderStatus(str, Enum): |
| PENDING = "PENDING" |
| FILLED = "FILLED" |
| PARTIAL = "PARTIAL" |
| CANCELLED = "CANCELLED" |
| REJECTED = "REJECTED" |
|
|
|
|
| class PositionSide(str, Enum): |
| LONG = "LONG" |
| SHORT = "SHORT" |
|
|
|
|
| class StrategyStatus(str, Enum): |
| RUNNING = "RUNNING" |
| STOPPED = "STOPPED" |
| ERROR = "ERROR" |
|
|
|
|
| class MarketData(BaseModel): |
| symbol: str |
| name: str = "" |
| exchange: str = "" |
| category: str = "" |
| open: float |
| high: float |
| low: float |
| close: float |
| volume: int |
| timestamp: datetime |
| bid: float = 0.0 |
| ask: float = 0.0 |
| turnover: float = 0.0 |
| open_interest: int = 0 |
| pre_close: float = 0.0 |
| pre_settlement: float = 0.0 |
| settlement: float = 0.0 |
| change_pct: float = 0.0 |
|
|
|
|
| class KlineData(BaseModel): |
| symbol: str |
| interval: str = "1m" |
| open: float |
| high: float |
| low: float |
| close: float |
| volume: int |
| timestamp: datetime |
|
|
|
|
| class OrderRequest(BaseModel): |
| symbol: str |
| side: OrderSide |
| order_type: OrderType = OrderType.MARKET |
| quantity: int = Field(gt=0) |
| price: float | None = None |
| stop_price: float | None = None |
| strategy_id: str | None = None |
|
|
|
|
| class OrderResponse(BaseModel): |
| order_id: str |
| symbol: str |
| side: OrderSide |
| order_type: OrderType |
| quantity: int |
| filled_quantity: int = 0 |
| price: float | None = None |
| avg_price: float = 0.0 |
| status: OrderStatus |
| strategy_id: str | None = None |
| created_at: datetime |
| updated_at: datetime |
|
|
|
|
| class Position(BaseModel): |
| symbol: str |
| side: PositionSide |
| quantity: int |
| avg_price: float |
| current_price: float = 0.0 |
| unrealized_pnl: float = 0.0 |
| realized_pnl: float = 0.0 |
| margin: float = 0.0 |
| leverage: int = 10 |
|
|
|
|
| class AccountInfo(BaseModel): |
| total_balance: float = 1_000_000.0 |
| available_balance: float = 1_000_000.0 |
| used_margin: float = 0.0 |
| unrealized_pnl: float = 0.0 |
| realized_pnl: float = 0.0 |
| positions: list[Position] = [] |
|
|
|
|
| class StrategyConfig(BaseModel): |
| strategy_id: str |
| strategy_type: str |
| symbol: str |
| params: dict = {} |
| status: StrategyStatus = StrategyStatus.STOPPED |
|
|
|
|
| class StrategyPerformance(BaseModel): |
| strategy_id: str |
| total_trades: int = 0 |
| winning_trades: int = 0 |
| losing_trades: int = 0 |
| total_pnl: float = 0.0 |
| max_drawdown: float = 0.0 |
| sharpe_ratio: float = 0.0 |
| win_rate: float = 0.0 |
|
|
|
|
| class TradeRecord(BaseModel): |
| trade_id: str |
| order_id: str |
| symbol: str |
| side: OrderSide |
| quantity: int |
| price: float |
| pnl: float = 0.0 |
| strategy_id: str | None = None |
| timestamp: datetime |
|
|