102 lines
3.4 KiB
Python
102 lines
3.4 KiB
Python
"""
|
|
Trading Configuration Module
|
|
Contains all configuration settings for the trading system.
|
|
"""
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Dict
|
|
import os
|
|
|
|
# Try to load environment variables if python-dotenv is available
|
|
try:
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
except ImportError:
|
|
# python-dotenv not installed, will use os.getenv with defaults
|
|
pass
|
|
|
|
@dataclass
|
|
class AlpacaConfig:
|
|
"""Alpaca API configuration"""
|
|
api_key: str = os.getenv('ALPACA_API_KEY', 'PKXR08ET6CSGV5QFS89E')
|
|
secret_key: str = os.getenv('ALPACA_SECRET_KEY', '5ILlNGVM7WfPwJk8kPRlHhQwDO022H19RWBOkwgd')
|
|
base_url: str = 'https://paper-api.alpaca.markets' # Paper trading URL
|
|
data_url: str = 'https://data.alpaca.markets'
|
|
|
|
@dataclass
|
|
class TradingConfig:
|
|
"""Main trading configuration"""
|
|
# Strategy Selection
|
|
strategy_type: str = os.getenv('STRATEGY_TYPE', 'enhanced') # 'conservative' or 'enhanced'
|
|
|
|
# Symbol to trade
|
|
symbol: str = os.getenv('SYMBOL', 'ETH/USD')
|
|
|
|
# Position sizing
|
|
max_position_size: float = float(os.getenv('MAX_POSITION_SIZE', '0.95')) # Maximum 95% of portfolio
|
|
risk_per_trade: float = float(os.getenv('RISK_PER_TRADE', '0.02')) # Risk 2% per trade
|
|
|
|
# Trading parameters
|
|
trade_cost: float = 0.0005 # 0.05% trading cost
|
|
cooldown_hours: int = 24 # Hours between signals
|
|
|
|
# Risk management
|
|
max_drawdown_limit: float = float(os.getenv('MAX_DRAWDOWN_LIMIT', '0.15')) # Stop trading if 15% drawdown
|
|
daily_loss_limit: float = float(os.getenv('DAILY_LOSS_LIMIT', '0.05')) # Stop trading if 5% daily loss
|
|
|
|
# Timeframe
|
|
timeframe: str = 'Hour' # Trading timeframe
|
|
|
|
# Strategy parameters
|
|
ema_fast: int = 12
|
|
ema_slow: int = 30
|
|
ema_trend: int = 80
|
|
rsi_period: int = 14
|
|
macd_fast: int = 12
|
|
macd_slow: int = 26
|
|
macd_signal: int = 9
|
|
|
|
@dataclass
|
|
class StrategyConfig:
|
|
"""Strategy-specific configuration"""
|
|
# Entry conditions
|
|
min_trend_threshold: float = 1.02 # Must be 2% above major trend
|
|
min_momentum_threshold: float = 0.02 # 2% momentum required
|
|
rsi_oversold: float = 45
|
|
rsi_overbought: float = 75
|
|
volume_threshold: float = 0.7
|
|
|
|
# Exit conditions
|
|
trailing_stops: Dict[float, float] = None
|
|
emergency_stop_days: int = 7
|
|
emergency_stop_loss: float = -0.10
|
|
trend_break_threshold: float = 0.85
|
|
|
|
def __post_init__(self):
|
|
if self.trailing_stops is None:
|
|
self.trailing_stops = {
|
|
2.00: 0.60, # 200%+ profit: 40% trailing stop
|
|
1.50: 0.65, # 150%+ profit: 35% trailing stop
|
|
1.00: 0.70, # 100%+ profit: 30% trailing stop
|
|
0.75: 0.75, # 75%+ profit: 25% trailing stop
|
|
0.50: 0.78, # 50%+ profit: 22% trailing stop
|
|
0.25: 0.80, # 25%+ profit: 20% trailing stop
|
|
0.10: 0.85, # 10%+ profit: 15% trailing stop
|
|
0.00: 0.88 # < 10% profit: 12% trailing stop
|
|
}
|
|
|
|
@dataclass
|
|
class LoggingConfig:
|
|
"""Logging configuration"""
|
|
log_level: str = 'INFO'
|
|
log_file: str = 'logs/trading.log'
|
|
log_format: str = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
max_file_size: int = 10 * 1024 * 1024 # 10MB
|
|
backup_count: int = 5
|
|
|
|
# Global configuration instances
|
|
alpaca_config = AlpacaConfig()
|
|
trading_config = TradingConfig()
|
|
strategy_config = StrategyConfig()
|
|
logging_config = LoggingConfig()
|