Files
DinQuant/backend_api_python/app/config/data_sources.py
T

143 lines
4.1 KiB
Python
Raw Normal View History

2025-12-29 03:06:49 +08:00
"""
Data source configuration
2025-12-29 03:06:49 +08:00
"""
2025-12-29 03:06:49 +08:00
import os
2025-12-29 03:06:49 +08:00
class MetaDataSourceConfig(type):
@property
def DEFAULT_TIMEOUT(cls):
from app.utils.config_loader import load_addon_config
val = load_addon_config().get("data_source", {}).get("timeout")
return int(val) if val is not None else int(os.getenv("DATA_SOURCE_TIMEOUT", 30))
2025-12-29 03:06:49 +08:00
@property
def RETRY_COUNT(cls):
from app.utils.config_loader import load_addon_config
val = load_addon_config().get("data_source", {}).get("retry_count")
return int(val) if val is not None else int(os.getenv("DATA_SOURCE_RETRY", 3))
2025-12-29 03:06:49 +08:00
@property
def RETRY_BACKOFF(cls):
from app.utils.config_loader import load_addon_config
val = load_addon_config().get("data_source", {}).get("retry_backoff")
return float(val) if val is not None else float(os.getenv("DATA_SOURCE_RETRY_BACKOFF", 0.5))
2025-12-29 03:06:49 +08:00
class DataSourceConfig(metaclass=MetaDataSourceConfig):
"""General data source configuration."""
2025-12-29 03:06:49 +08:00
pass
class MetaFinnhubConfig(type):
@property
def BASE_URL(cls):
return "https://finnhub.io/api/v1"
@property
def TIMEOUT(cls):
from app.utils.config_loader import load_addon_config
val = load_addon_config().get("finnhub", {}).get("timeout")
return int(val) if val is not None else int(os.getenv("FINNHUB_TIMEOUT", 10))
2025-12-29 03:06:49 +08:00
@property
def RATE_LIMIT(cls):
from app.utils.config_loader import load_addon_config
val = load_addon_config().get("finnhub", {}).get("rate_limit")
return int(val) if val is not None else int(os.getenv("FINNHUB_RATE_LIMIT", 60))
2025-12-29 03:06:49 +08:00
@property
def RATE_LIMIT_PERIOD(cls):
return 60
class FinnhubConfig(metaclass=MetaFinnhubConfig):
"""Finnhub data source configuration"""
2025-12-29 03:06:49 +08:00
2025-12-29 03:06:49 +08:00
class MetaTiingoConfig(type):
@property
def BASE_URL(cls):
return "https://api.tiingo.com/tiingo"
@property
def TIMEOUT(cls):
from app.utils.config_loader import load_addon_config
val = load_addon_config().get("tiingo", {}).get("timeout")
return int(val) if val is not None else int(os.getenv("TIINGO_TIMEOUT", 10))
2025-12-29 03:06:49 +08:00
class TiingoConfig(metaclass=MetaTiingoConfig):
"""Tiingo data source configuration"""
2025-12-29 03:06:49 +08:00
2025-12-29 03:06:49 +08:00
class MetaYFinanceConfig(type):
@property
def TIMEOUT(cls):
from app.utils.config_loader import load_addon_config
val = load_addon_config().get("yfinance", {}).get("timeout")
return int(val) if val is not None else int(os.getenv("YFINANCE_TIMEOUT", 30))
2025-12-29 03:06:49 +08:00
@property
def INTERVAL_MAP(cls):
return {"1m": "1m", "5m": "5m", "15m": "15m", "30m": "30m", "1H": "1h", "4H": "4h", "1D": "1d", "1W": "1wk"}
2025-12-29 03:06:49 +08:00
class YFinanceConfig(metaclass=MetaYFinanceConfig):
"""Yahoo Finance data source configuration"""
2025-12-29 03:06:49 +08:00
2025-12-29 03:06:49 +08:00
class MetaCCXTConfig(type):
@property
def DEFAULT_EXCHANGE(cls):
from app.utils.config_loader import load_addon_config
val = load_addon_config().get("ccxt", {}).get("default_exchange")
return val if val else os.getenv("CCXT_DEFAULT_EXCHANGE", "binance")
2025-12-29 03:06:49 +08:00
@property
def TIMEOUT(cls):
from app.utils.config_loader import load_addon_config
val = load_addon_config().get("ccxt", {}).get("timeout")
return int(val) if val is not None else int(os.getenv("CCXT_TIMEOUT", 10000))
2025-12-29 03:06:49 +08:00
@property
def ENABLE_RATE_LIMIT(cls):
return True
@property
def TIMEFRAME_MAP(cls):
return {"1m": "1m", "5m": "5m", "15m": "15m", "30m": "30m", "1H": "1h", "4H": "4h", "1D": "1d", "1W": "1w"}
2025-12-29 03:06:49 +08:00
@property
def PROXY(cls):
# 1) Local proxy helpers from backend_api_python/.env
2025-12-29 03:06:49 +08:00
# PROXY_URL has the highest priority if provided.
proxy_url = (os.getenv("PROXY_URL") or "").strip()
2025-12-29 03:06:49 +08:00
if proxy_url:
return proxy_url
# 2) Standard proxy envs (fallback)
for key in ["HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY"]:
v = (os.getenv(key) or "").strip()
2025-12-29 03:06:49 +08:00
if v:
return v
return ""
2025-12-29 03:06:49 +08:00
class CCXTConfig(metaclass=MetaCCXTConfig):
"""CCXT cryptocurrency data source configuration."""
2025-12-29 03:06:49 +08:00
pass