Files
zhixing-system/zhixing-server/src/zhixing_server/bootstrap/config.py
T

42 lines
1.3 KiB
Python
Raw Normal View History

"""Environment-backed application configuration."""
from decimal import Decimal
from functools import lru_cache
from pathlib import Path
from typing import Literal
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
"""Validated process configuration at the application boundary."""
app_name: str = "Zhixing Server"
app_env: Literal["development", "test", "production"] = "development"
log_level: str = "INFO"
database_url: str = "postgresql://zhixing:zhixing@localhost:5432/zhixing"
tushare_token: str = ""
market_data_csv_root: Path = Path("./data/market-data")
market_data_coverage_threshold: Decimal = Decimal("0.99")
market_data_max_workers: int = 4
market_data_request_interval_seconds: float = 0.2
market_data_max_retries: int = 3
market_data_retry_backoff_seconds: float = 1.0
market_data_advisory_lock_key: int = 7_380_521
model_config = SettingsConfigDict(
env_file=".env",
env_prefix="ZHIXING_",
extra="ignore",
)
@lru_cache
def get_settings() -> Settings:
"""Return one immutable-by-convention configuration object per process.
Returns:
Settings populated from defaults, `.env`, and process environment variables.
"""
return Settings()