File size: 1,790 Bytes
cafdd88
 
 
 
 
 
 
 
 
 
 
 
5dafb0f
cafdd88
 
2b62855
cafdd88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
from typing import Optional
from pydantic import BaseModel, Field, SecretStr

class Settings(BaseModel):
    """
    Application Configuration.
    Loads from environment variables via os.getenv.
    """
    
    # API Keys
    HF_TOKEN: Optional[SecretStr] = Field(default_factory=lambda: SecretStr(os.getenv("HF_TOKEN", "")) if os.getenv("HF_TOKEN") else None, description="Hugging Face API Token")
    BYTEZ_API_KEY: Optional[SecretStr] = Field(default_factory=lambda: SecretStr(os.getenv("BYTEZ_API_KEY", "")) if os.getenv("BYTEZ_API_KEY") else None, description="Bytez API Key")
    
    # Data Configuration
    DATA_DIR: str = Field(default="./data", description="Directory to store static data files")
    DATA_CACHE_DIR: str = Field(default="./data_cache", description="Directory to store cached market data")
    SECTOR_MAP_FILE: str = Field(default="./data/sector_map.json", description="Path to sector mapping cache")
    
    # Optimization Defaults
    MAX_WEIGHT: float = Field(default=0.05, description="Maximum weight for a single asset")
    MIN_WEIGHT: float = Field(default=0.00, description="Minimum weight for a single asset")
    
    # Universe
    BENCHMARK_TICKER: str = Field(default="^GSPC", description="Benchmark Ticker (S&P 500)")
    
    # System
    LOG_LEVEL: str = Field(default="INFO", description="Logging level")


# Global settings instance
try:
    settings = Settings()
except Exception as e:
    print(f"WARNING: Settings failed to load. Using defaults/env vars might be missing: {e}")
    # Fallback to empty settings if possible or re-raise if critical
    # For now, let's allow it to crash safely or provide a dummy
    # But if HF_TOKEN is None, the AI feature will just fail gracefully later
    settings = Settings(HF_TOKEN=None)