Refactor code for improved readability and consistency

- Cleaned up whitespace and formatting in various files including http.py, language.py, logger.py, safe_exec.py, and SQL migration scripts.
- Consolidated import statements and removed unnecessary blank lines.
- Updated logging configuration for better clarity.
- Enhanced the safe execution code with improved error handling and logging.
- Removed commented-out code and unnecessary variables in backfill_zero_trades.py and other scripts.
- Added a pyproject.toml for Ruff and Vulture configuration.
- Introduced requirements-dev.txt for development dependencies.
- Removed commented-out stock entries in init.sql for cleaner migration scripts.
This commit is contained in:
dienakdz
2026-04-09 14:30:51 +07:00
parent 103055b3df
commit 87f2845483
157 changed files with 19026 additions and 17773 deletions
+41 -62
View File
@@ -1,30 +1,36 @@
"""
Data source configuration
"""
import os
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))
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))
@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))
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))
@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))
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))
class DataSourceConfig(metaclass=MetaDataSourceConfig):
"""General data source configuration."""
pass
@@ -36,14 +42,16 @@ class MetaFinnhubConfig(type):
@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))
val = load_addon_config().get("finnhub", {}).get("timeout")
return int(val) if val is not None else int(os.getenv("FINNHUB_TIMEOUT", 10))
@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))
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))
@property
def RATE_LIMIT_PERIOD(cls):
@@ -53,6 +61,7 @@ class MetaFinnhubConfig(type):
class FinnhubConfig(metaclass=MetaFinnhubConfig):
"""Finnhub data source configuration"""
class MetaTiingoConfig(type):
@property
def BASE_URL(cls):
@@ -61,49 +70,46 @@ class MetaTiingoConfig(type):
@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))
val = load_addon_config().get("tiingo", {}).get("timeout")
return int(val) if val is not None else int(os.getenv("TIINGO_TIMEOUT", 10))
class TiingoConfig(metaclass=MetaTiingoConfig):
"""Tiingo data source configuration"""
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))
val = load_addon_config().get("yfinance", {}).get("timeout")
return int(val) if val is not None else int(os.getenv("YFINANCE_TIMEOUT", 30))
@property
def INTERVAL_MAP(cls):
return {
'1m': '1m',
'5m': '5m',
'15m': '15m',
'30m': '30m',
'1H': '1h',
'4H': '4h',
'1D': '1d',
'1W': '1wk'
}
return {"1m": "1m", "5m": "5m", "15m": "15m", "30m": "30m", "1H": "1h", "4H": "4h", "1D": "1d", "1W": "1wk"}
class YFinanceConfig(metaclass=MetaYFinanceConfig):
"""Yahoo Finance data source configuration"""
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')
val = load_addon_config().get("ccxt", {}).get("default_exchange")
return val if val else os.getenv("CCXT_DEFAULT_EXCHANGE", "binance")
@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))
val = load_addon_config().get("ccxt", {}).get("timeout")
return int(val) if val is not None else int(os.getenv("CCXT_TIMEOUT", 10000))
@property
def ENABLE_RATE_LIMIT(cls):
@@ -111,53 +117,26 @@ class MetaCCXTConfig(type):
@property
def TIMEFRAME_MAP(cls):
return {
'1m': '1m',
'5m': '5m',
'15m': '15m',
'30m': '30m',
'1H': '1h',
'4H': '4h',
'1D': '1d',
'1W': '1w'
}
return {"1m": "1m", "5m": "5m", "15m": "15m", "30m": "30m", "1H": "1h", "4H": "4h", "1D": "1d", "1W": "1w"}
@property
def PROXY(cls):
# 1) Local proxy helpers from backend_api_python/.env
# PROXY_URL has the highest priority if provided.
proxy_url = (os.getenv('PROXY_URL') or '').strip()
proxy_url = (os.getenv("PROXY_URL") or "").strip()
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()
for key in ["HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY"]:
v = (os.getenv(key) or "").strip()
if v:
return v
return ''
return ""
class CCXTConfig(metaclass=MetaCCXTConfig):
"""CCXT cryptocurrency data source configuration."""
pass
class MetaAkshareConfig(type):
@property
def TIMEOUT(cls):
from app.utils.config_loader import load_addon_config
val = load_addon_config().get('akshare', {}).get('timeout')
return int(val) if val is not None else int(os.getenv('AKSHARE_TIMEOUT', 30))
@property
def PERIOD_MAP(cls):
return {
'1D': 'daily',
'1W': 'weekly'
}
class AkshareConfig(metaclass=MetaAkshareConfig):
"""Akshare data source configuration"""