Crypto trading bot: engine, brokers, backtester, dashboard, deploy
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.
This commit is contained in:
1 parent
98028248c2
commit
9c3bee87ac
73 files changed
+9759
-1
No files matched your search
@@ -0,0 +1,46 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
from collections.abc import Sequence
|
||||
|
||||
from app.market.base import MarketData
|
||||
from app.schemas import Candle
|
||||
|
||||
|
||||
class FakeMarketData(MarketData):
|
||||
"""In-memory market data for tests and offline demos."""
|
||||
|
||||
def __init__(self, candles: Sequence[Candle] | None = None) -> None:
|
||||
self.candles: list[Candle] = list(candles or [])
|
||||
|
||||
@classmethod
|
||||
def from_closes(cls, closes: Sequence[float]) -> FakeMarketData:
|
||||
candles = [
|
||||
Candle(
|
||||
ts=1_700_000_000_000 + i * 60_000,
|
||||
open=close,
|
||||
high=close,
|
||||
low=close,
|
||||
close=close,
|
||||
volume=1.0,
|
||||
)
|
||||
for i, close in enumerate(closes)
|
||||
]
|
||||
return cls(candles)
|
||||
|
||||
@classmethod
|
||||
def sine_wave(cls, n: int = 200, amplitude: float = 100.0, period: int = 20) -> FakeMarketData:
|
||||
base = 1000.0
|
||||
closes = [base + amplitude * math.sin(2 * math.pi * i / period) for i in range(n)]
|
||||
return cls.from_closes(closes)
|
||||
|
||||
def append(self, candle: Candle) -> None:
|
||||
self.candles.append(candle)
|
||||
|
||||
async def fetch_candles(self, symbol: str, timeframe: str, limit: int) -> list[Candle]:
|
||||
return self.candles[-limit:]
|
||||
|
||||
async def fetch_price(self, symbol: str) -> float:
|
||||
if not self.candles:
|
||||
raise ValueError("no candles available")
|
||||
return self.candles[-1].close
|
||||
Reference in new issue
Block a user