2026-08-03 13:47:24 +08:00
|
|
|
"""Environment-backed application configuration."""
|
|
|
|
|
|
2026-08-05 17:57:32 +08:00
|
|
|
from decimal import Decimal
|
2026-08-03 13:47:24 +08:00
|
|
|
from functools import lru_cache
|
2026-08-05 17:57:32 +08:00
|
|
|
from pathlib import Path
|
2026-08-03 13:47:24 +08:00
|
|
|
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"
|
2026-08-05 17:57:32 +08:00
|
|
|
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
|
2026-08-03 13:47:24 +08:00
|
|
|
|
|
|
|
|
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()
|