- Introduced a new `strategies` package containing the core structure for trading strategies, including `BaseStrategy`, `StrategyFactory`, and various strategy implementations (EMA, RSI, MACD). - Added utility functions for signal detection and validation in `strategies/utils.py`, enhancing modularity and maintainability. - Updated `pyproject.toml` to include the new `strategies` package in the build configuration. - Implemented comprehensive unit tests for the strategy foundation components, ensuring reliability and adherence to project standards. These changes establish a solid foundation for the strategy engine, aligning with project goals for modularity, performance, and maintainability.
72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
"""
|
|
Strategy Data Types and Signal Definitions
|
|
|
|
This module provides data types for strategy calculations, signals,
|
|
and results in a standardized format.
|
|
"""
|
|
|
|
from dataclasses import dataclass
|
|
from datetime import datetime
|
|
from typing import Dict, Optional, Any, List
|
|
from enum import Enum
|
|
|
|
|
|
class SignalType(str, Enum):
|
|
"""
|
|
Types of trading signals that strategies can generate.
|
|
"""
|
|
BUY = "buy"
|
|
SELL = "sell"
|
|
HOLD = "hold"
|
|
ENTRY_LONG = "entry_long"
|
|
EXIT_LONG = "exit_long"
|
|
ENTRY_SHORT = "entry_short"
|
|
EXIT_SHORT = "exit_short"
|
|
STOP_LOSS = "stop_loss"
|
|
TAKE_PROFIT = "take_profit"
|
|
|
|
|
|
@dataclass
|
|
class StrategySignal:
|
|
"""
|
|
Container for individual strategy signals.
|
|
|
|
Attributes:
|
|
timestamp: Signal timestamp (right-aligned with candle)
|
|
symbol: Trading symbol
|
|
timeframe: Candle timeframe
|
|
signal_type: Type of signal (buy/sell/hold etc.)
|
|
price: Price at which signal was generated
|
|
confidence: Signal confidence score (0.0 to 1.0)
|
|
metadata: Additional signal metadata (e.g., indicator values)
|
|
"""
|
|
timestamp: datetime
|
|
symbol: str
|
|
timeframe: str
|
|
signal_type: SignalType
|
|
price: float
|
|
confidence: float = 1.0
|
|
metadata: Optional[Dict[str, Any]] = None
|
|
|
|
|
|
@dataclass
|
|
class StrategyResult:
|
|
"""
|
|
Container for strategy calculation results.
|
|
|
|
Attributes:
|
|
timestamp: Candle timestamp (right-aligned)
|
|
symbol: Trading symbol
|
|
timeframe: Candle timeframe
|
|
strategy_name: Name of the strategy that generated this result
|
|
signals: List of signals generated for this timestamp
|
|
indicators_used: Dictionary of indicator values used in calculation
|
|
metadata: Additional calculation metadata
|
|
"""
|
|
timestamp: datetime
|
|
symbol: str
|
|
timeframe: str
|
|
strategy_name: str
|
|
signals: List[StrategySignal]
|
|
indicators_used: Dict[str, float]
|
|
metadata: Optional[Dict[str, Any]] = None |