mirror of
https://github.com/silencesdg/mt5_python_ea_suite.git
synced 2026-07-28 03:07:48 +00:00
4cb4f4a15e
- 重构核心模块:DataProvider 依赖注入、RiskController 门面、信号注册表 - 新增 FastAPI 代理服务 (run/server.py),支持局域网远程调用 MT5 - 新增 RemoteDataProvider + AttrDict,远端无缝替代 LiveDataProvider - 新增序列化模块,MT5 对象转 JSON 兼容格式 - 重构入口点至 run/ 包,支持 python -m run.realtime/server/backtest/optimize - 更新 CLAUDE.md 文档 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
import numpy as np
|
|
|
|
|
|
def _to_native(val):
|
|
"""numpy 类型转 Python 原生类型"""
|
|
if isinstance(val, (np.integer,)):
|
|
return int(val)
|
|
if isinstance(val, (np.floating,)):
|
|
return float(val)
|
|
if isinstance(val, np.ndarray):
|
|
return val.tolist()
|
|
return val
|
|
|
|
|
|
def _mt5_to_dict(obj):
|
|
"""将 MT5 对象转为 dict,兼容 _asdict() / _fields / __dict__"""
|
|
if hasattr(obj, '_asdict'):
|
|
return {k: _to_native(v) for k, v in obj._asdict().items()}
|
|
if hasattr(obj, '_fields'):
|
|
return {f: _to_native(getattr(obj, f)) for f in obj._fields}
|
|
if hasattr(obj, '__dict__'):
|
|
return {k: _to_native(v) for k, v in obj.__dict__.items()}
|
|
return {}
|
|
|
|
|
|
def serialize_account_info(info):
|
|
return _mt5_to_dict(info) if info else None
|
|
|
|
|
|
def serialize_position(pos):
|
|
return _mt5_to_dict(pos) if pos else None
|
|
|
|
|
|
def serialize_symbol_info(info):
|
|
return _mt5_to_dict(info) if info else None
|
|
|
|
|
|
def serialize_order_result(result):
|
|
return _mt5_to_dict(result) if result else None
|
|
|
|
|
|
def serialize_rates(rates):
|
|
if rates is None:
|
|
return None
|
|
names = rates.dtype.names
|
|
return [{name: _to_native(row[name]) for name in names} for row in rates]
|