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
+31 -27
View File
@@ -1,37 +1,40 @@
"""
Database and cache configuration
"""
import os
class MetaRedisConfig(type):
"""Redis configuration"""
"""Redis configuration"""
@property
def HOST(cls):
return os.getenv('REDIS_HOST', 'localhost')
return os.getenv("REDIS_HOST", "localhost")
@property
def PORT(cls):
return int(os.getenv('REDIS_PORT', 6379))
return int(os.getenv("REDIS_PORT", 6379))
@property
def PASSWORD(cls):
return os.getenv('REDIS_PASSWORD', None)
return os.getenv("REDIS_PASSWORD", None)
@property
def DB(cls):
return int(os.getenv('REDIS_DB', 0))
return int(os.getenv("REDIS_DB", 0))
@property
def CONNECT_TIMEOUT(cls):
return int(os.getenv('REDIS_CONNECT_TIMEOUT', 5))
return int(os.getenv("REDIS_CONNECT_TIMEOUT", 5))
@property
def SOCKET_TIMEOUT(cls):
return int(os.getenv('REDIS_SOCKET_TIMEOUT', 5))
return int(os.getenv("REDIS_SOCKET_TIMEOUT", 5))
@property
def MAX_CONNECTIONS(cls):
return int(os.getenv('REDIS_MAX_CONNECTIONS', 10))
return int(os.getenv("REDIS_MAX_CONNECTIONS", 10))
class RedisConfig(metaclass=MetaRedisConfig):
@@ -50,27 +53,27 @@ class MetaCacheConfig(type):
def ENABLED(cls):
# Forced to be off by default unless explicitly enabled by an environment variable
return os.getenv('CACHE_ENABLED', 'False').lower() == 'true'
return os.getenv("CACHE_ENABLED", "False").lower() == "true"
@property
def DEFAULT_EXPIRE(cls):
return int(os.getenv('CACHE_EXPIRE', 300))
return int(os.getenv("CACHE_EXPIRE", 300))
@property
def KLINE_CACHE_TTL(cls):
return {
'1m': 5, # K-line cache for 1 minute and 5 seconds
'3m': 30, # 3 minutes K-line cache 30 seconds
'5m': 60, # 5 minutes K-line cache 1 minute
'15m': 300, # 15 minutes K-line cache 5 minutes
'30m': 300, # 30 minutes K-line cache 5 minutes
'1H': 300, # 1 hour K-line cache for 5 minutes
'4H': 300, # 4 hours K-line cache for 5 minutes
'1D': 300, # Daily K-line cache for 5 minutes
"1m": 5, # K-line cache for 1 minute and 5 seconds
"3m": 30, # 3 minutes K-line cache 30 seconds
"5m": 60, # 5 minutes K-line cache 1 minute
"15m": 300, # 15 minutes K-line cache 5 minutes
"30m": 300, # 30 minutes K-line cache 5 minutes
"1H": 300, # 1 hour K-line cache for 5 minutes
"4H": 300, # 4 hours K-line cache for 5 minutes
"1D": 300, # Daily K-line cache for 5 minutes
# Compatible with lowercase
'1h': 300,
'4h': 300,
'1d': 300,
"1h": 300,
"4h": 300,
"1d": 300,
}
@property
@@ -84,4 +87,5 @@ class MetaCacheConfig(type):
class CacheConfig(metaclass=MetaCacheConfig):
"""Cache configuration."""
pass