Files
trader-bot/backend/app/core/strategy/base.py
tika 4df8d53b1a 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>
2026-02-24 23:25:51 +01:00

67 lines
1.9 KiB
Python

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."""
...