tradusai/config/settings.py
2025-12-04 00:38:23 +08:00

80 lines
3.0 KiB
Python

"""
Configuration settings for Binance WebSocket data ingestion system
"""
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
"""Application settings with validation"""
model_config = SettingsConfigDict(
env_file=".env",
case_sensitive=True,
extra="ignore" # Ignore extra fields from environment
)
# Binance WebSocket Configuration
BINANCE_WS_BASE_URL: str = "wss://fstream.binance.com"
SYMBOL: str = "btcusdt"
# Stream subscriptions
KLINE_INTERVALS: str = "5m,15m,1h,4h" # Multiple kline intervals (comma-separated)
DEPTH_LEVEL: int = 20 # Top 20 order book levels
# Redis Configuration
REDIS_HOST: str = "redis"
REDIS_PORT: int = 6379
REDIS_DB: int = 0
REDIS_PASSWORD: str = ""
# Redis Stream Keys (prefix, actual keys are dynamic based on intervals)
REDIS_STREAM_KLINE_PREFIX: str = "binance:raw:kline" # Will be: binance:raw:kline:5m, etc.
REDIS_STREAM_DEPTH: str = "binance:raw:depth:20"
REDIS_STREAM_TRADE: str = "binance:raw:trade"
@property
def kline_intervals_list(self) -> list:
"""Parse kline intervals from comma-separated string"""
return [interval.strip() for interval in self.KLINE_INTERVALS.split(',')]
# Stream Configuration
REDIS_STREAM_MAXLEN: int = 10000 # Keep last 10k messages per stream
# Reconnection Strategy
RECONNECT_INITIAL_DELAY: float = 1.0 # Initial delay in seconds
RECONNECT_MAX_DELAY: float = 60.0 # Max delay in seconds
RECONNECT_MULTIPLIER: float = 2.0 # Exponential backoff multiplier
MAX_RECONNECT_ATTEMPTS: int = 100 # -1 for unlimited
# Memory Protection
MAX_BUFFER_SIZE: int = 1000 # Max messages in memory buffer
RATE_LIMIT_MESSAGES_PER_SEC: int = 1000 # Max messages processed per second
# Message Deduplication
DEDUP_CACHE_SIZE: int = 10000 # Size of deduplication cache
DEDUP_TTL_SECONDS: int = 300 # TTL for dedup entries (5 minutes)
# Monitoring
HEALTH_CHECK_INTERVAL: int = 30 # Health check interval in seconds
LOG_LEVEL: str = "INFO"
# LLM Gate Configuration (极简门控 - 频率为主,量化初筛)
LLM_GATE_ENABLED: bool = True # 启用 LLM 门控
# 数据要求
LLM_MIN_CANDLES: int = 100 # 最少K线数量
# 信号质量(极简 - 只检查综合得分)
LLM_MIN_COMPOSITE_SCORE: float = 0.0 # Gate关闭 - 每次都调用LLM
# 频率限制(核心控制!)
LLM_MAX_CALLS_PER_DAY: int = 12 # 每天最多调用次数
LLM_MIN_INTERVAL_MINUTES: int = 15 # 最小调用间隔(分钟)
# 盈利空间过滤(过滤低利润机会)
MIN_PROFIT_PCT: float = 1.0 # 最小盈利空间百分比,低于此值的机会不给操作建议
PREFER_INTRADAY: bool = True # 优先日内短线交易建议
settings = Settings()