feat: trading bot MVP — ICT Order Block + Liquidity Sweep strategy
Full-stack trading bot with: - FastAPI backend with ICT strategy (Order Block + Liquidity Sweep detection) - Backtester engine with rolling window, spread simulation, and performance metrics - Hybrid market data service (yfinance + TwelveData with rate limiting + SQLite cache) - Simulated exchange for paper trading - React/TypeScript frontend with TradingView lightweight-charts v5 - Live dashboard with candlestick chart, OHLC legend, trade markers - Backtest page with configurable parameters, equity curve, and trade table - WebSocket support for real-time updates - Bot runner with asyncio loop for automated trading Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
66
backend/app/core/strategy/base.py
Normal file
66
backend/app/core/strategy/base.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional
|
||||
|
||||
import pandas as pd
|
||||
|
||||
|
||||
@dataclass
|
||||
class OrderBlockZone:
|
||||
"""Zone Order Block à surveiller."""
|
||||
id: str
|
||||
direction: str # "bullish" | "bearish"
|
||||
top: float # Haut de la zone
|
||||
bottom: float # Bas de la zone
|
||||
origin_time: pd.Timestamp
|
||||
mitigated: bool = False # True si le prix a traversé la zone
|
||||
|
||||
|
||||
@dataclass
|
||||
class LiquidityLevel:
|
||||
"""Niveau de liquidité (Equal H/L)."""
|
||||
id: str
|
||||
direction: str # "high" | "low"
|
||||
price: float
|
||||
origin_time: pd.Timestamp
|
||||
swept: bool = False # True si le prix a dépassé ce niveau
|
||||
|
||||
|
||||
@dataclass
|
||||
class TradeSignal:
|
||||
"""Signal de trading généré par la stratégie."""
|
||||
direction: str # "buy" | "sell"
|
||||
entry_price: float
|
||||
stop_loss: float
|
||||
take_profit: float
|
||||
signal_type: str # description du setup
|
||||
time: pd.Timestamp
|
||||
order_block: Optional[OrderBlockZone] = None
|
||||
liquidity_level: Optional[LiquidityLevel] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class AnalysisResult:
|
||||
"""Résultat complet de l'analyse de la stratégie."""
|
||||
order_blocks: list[OrderBlockZone] = field(default_factory=list)
|
||||
liquidity_levels: list[LiquidityLevel] = field(default_factory=list)
|
||||
signals: list[TradeSignal] = field(default_factory=list)
|
||||
|
||||
|
||||
class AbstractStrategy(ABC):
|
||||
"""Interface commune pour toutes les stratégies."""
|
||||
|
||||
@abstractmethod
|
||||
def analyze(self, df: pd.DataFrame) -> AnalysisResult:
|
||||
"""
|
||||
Analyse un DataFrame de candles et retourne les zones,
|
||||
niveaux de liquidité et signaux d'entrée.
|
||||
|
||||
df doit avoir les colonnes : time, open, high, low, close, volume
|
||||
"""
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
def get_params(self) -> dict:
|
||||
"""Retourne les paramètres configurables de la stratégie."""
|
||||
...
|
||||
Reference in New Issue
Block a user