a
This commit is contained in:
parent
b41064f880
commit
f81e4fc04e
|
|
@ -29,7 +29,15 @@ except Exception:
|
|||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
from database.models import TradingConfig
|
||||
# 延迟导入,避免在trading_system中导入时因为缺少依赖而失败
|
||||
try:
|
||||
from database.models import TradingConfig
|
||||
except ImportError as e:
|
||||
TradingConfig = None
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.warning(f"无法导入TradingConfig: {e},配置管理器将无法使用数据库")
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -44,6 +52,11 @@ class ConfigManager:
|
|||
|
||||
def _load_from_db(self):
|
||||
"""从数据库加载配置"""
|
||||
if TradingConfig is None:
|
||||
logger.warning("TradingConfig未导入,无法从数据库加载配置")
|
||||
self._cache = {}
|
||||
return
|
||||
|
||||
try:
|
||||
configs = TradingConfig.get_all()
|
||||
for config in configs:
|
||||
|
|
@ -74,6 +87,11 @@ class ConfigManager:
|
|||
|
||||
def set(self, key, value, config_type='string', category='general', description=None):
|
||||
"""设置配置(同时更新数据库和缓存)"""
|
||||
if TradingConfig is None:
|
||||
logger.warning("TradingConfig未导入,无法更新数据库配置")
|
||||
self._cache[key] = value
|
||||
return
|
||||
|
||||
try:
|
||||
TradingConfig.set(key, value, config_type, category, description)
|
||||
self._cache[key] = value
|
||||
|
|
|
|||
|
|
@ -3,3 +3,7 @@ python-binance==1.0.19
|
|||
websocket-client==1.6.1
|
||||
aiohttp==3.9.1
|
||||
unicorn-binance-websocket-api==2.4.0
|
||||
|
||||
# 数据库依赖(用于从数据库读取配置)
|
||||
pymysql==1.1.0
|
||||
python-dotenv==1.0.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user