FastAPI backend with a single-strategy async engine, paper and Binance brokers, pure-python indicators, a backtester that shares the engine's portfolio math, and a Vue dashboard with a live WebSocket feed. Adds the Gitea Actions CI/CD workflow that deploys to Traefik via docker_default.
37 lines
811 B
Python
37 lines
811 B
Python
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass
|
|
from datetime import datetime
|
|
|
|
from app.models import OrderSide
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class Fill:
|
|
symbol: str
|
|
side: OrderSide
|
|
qty: float
|
|
price: float
|
|
fee: float
|
|
ts: datetime
|
|
|
|
@property
|
|
def notional(self) -> float:
|
|
return self.qty * self.price
|
|
|
|
|
|
class Broker(ABC):
|
|
"""Executes market orders. Paper and live brokers share this interface."""
|
|
|
|
@abstractmethod
|
|
async def buy(self, symbol: str, qty: float, ref_price: float) -> Fill:
|
|
raise NotImplementedError
|
|
|
|
@abstractmethod
|
|
async def sell(self, symbol: str, qty: float, ref_price: float) -> Fill:
|
|
raise NotImplementedError
|
|
|
|
async def close(self) -> None:
|
|
return None
|