重构项目架构,新增 MT5 代理服务

- 重构核心模块: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>
This commit is contained in:
silencesdg
2026-05-11 12:00:45 +08:00
co-authored by Claude Happy
parent e8226edd96
commit 4cb4f4a15e
46 changed files with 2993 additions and 2279 deletions
+11 -8
View File
@@ -36,8 +36,9 @@ class WaveTheoryStrategy(BaseStrategy):
def _identify_wave_points(self, df):
window_size = self.wave_period * 2 + 1
df['local_high'] = df['high'].rolling(window=window_size, center=False).max().shift(-self.wave_period)
df['local_low'] = df['low'].rolling(window=window_size, center=False).min().shift(-self.wave_period)
# 纯后向窗口,不使用 shift 避免未来函数
df['local_high'] = df['high'].rolling(window=window_size, center=False).max()
df['local_low'] = df['low'].rolling(window=window_size, center=False).min()
wave_points = pd.Series(0, index=df.index)
wave_points[df['high'] == df['local_high']] = 1
wave_points[df['low'] == df['local_low']] = -1
@@ -109,12 +110,13 @@ class WaveTheoryStrategy(BaseStrategy):
if current_price > upper_bound * 0.98 and current_momentum < 0: return -1
elif current_price < lower_bound * 1.02 and current_momentum > 0: return 1
else:
ema_alignment = (df['ema_short'].iloc[-1] > df['ema_medium'].iloc[-1] > df['ema_long'].iloc[-1])
ema_bullish = (df['ema_short'].iloc[-1] > df['ema_medium'].iloc[-1] > df['ema_long'].iloc[-1])
ema_bearish = (df['ema_short'].iloc[-1] < df['ema_medium'].iloc[-1] < df['ema_long'].iloc[-1])
if f'fib_0.618' in df.columns and not pd.isna(df[f'fib_0.618'].iloc[-1]):
fib_618 = df[f'fib_0.618'].iloc[-1]
if abs(current_price - fib_618) / fib_618 < 0.01:
if ema_alignment and current_momentum > 0: return 1
elif not ema_alignment and current_momentum < 0: return -1
if ema_bullish and current_momentum > 0: return 1
elif ema_bearish and current_momentum < 0: return -1
return 0
def run_backtest(self, df):
@@ -132,10 +134,11 @@ class WaveTheoryStrategy(BaseStrategy):
if current_price > upper_bound * 0.98 and current_momentum < 0: signals.iat[i] = -1
elif current_price < lower_bound * 1.02 and current_momentum > 0: signals.iat[i] = 1
else:
ema_alignment = (df['ema_short'].iloc[i] > df['ema_medium'].iloc[i] > df['ema_long'].iloc[i])
ema_bullish = (df['ema_short'].iloc[i] > df['ema_medium'].iloc[i] > df['ema_long'].iloc[i])
ema_bearish = (df['ema_short'].iloc[i] < df['ema_medium'].iloc[i] < df['ema_long'].iloc[i])
if f'fib_0.618' in df.columns and not pd.isna(df[f'fib_0.618'].iloc[i]):
fib_618 = df[f'fib_0.618'].iloc[i]
if abs(current_price - fib_618) / fib_618 < 0.01:
if ema_alignment and current_momentum > 0: signals.iat[i] = 1
elif not ema_alignment and current_momentum < 0: signals.iat[i] = -1
if ema_bullish and current_momentum > 0: signals.iat[i] = 1
elif ema_bearish and current_momentum < 0: signals.iat[i] = -1
return signals