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
@@ -3,17 +3,17 @@
# Cross-Sectional Strategy Indicator Example
# Momentum + RSI Composite Score
# ============================================================
#
#
# 使用方法:
# 1. 在交易助手中创建截面策略
# 2. 选择此指标作为策略指标
# 3. 配置标的列表、持仓大小、做多比例等参数
#
#
# 评分逻辑:
# - 动量因子 (20周期): 价格变化率,越高越好
# - RSI指标 (14周期): 反转RSI值,越低越好(100 - RSI
# - 综合评分: 70% 动量 + 30% RSI反转值
#
#
# ============================================================
# 截面策略指标
@@ -28,11 +28,11 @@ for symbol, df in data.items():
if len(df) < 20:
scores[symbol] = 0
continue
# === 1. 计算动量因子 (20周期) ===
# 动量 = (当前价格 / 20周期前价格 - 1) * 100
momentum = (df['close'].iloc[-1] / df['close'].iloc[-20] - 1) * 100
# === 2. 计算RSI指标 (14周期) ===
def calculate_rsi(prices, period=14):
"""计算RSI指标"""
@@ -42,18 +42,18 @@ for symbol, df in data.items():
rs = gain / loss
rsi = 100 - (100 / (1 + rs))
return rsi.iloc[-1]
rsi_value = calculate_rsi(df['close'], 14)
# === 3. 综合评分 ===
# 动量越高 = 评分越高
# RSI越低(超卖)= 评分越高(100 - RSI)
# 权重: 70% 动量 + 30% RSI反转值
momentum_score = momentum
rsi_score = 100 - rsi_value # 反转RSIRSI越低,评分越高)
composite_score = momentum_score * 0.7 + rsi_score * 0.3
scores[symbol] = composite_score
# === 可选: 手动指定排序 ===
+2 -2
View File
@@ -2,13 +2,13 @@
# 双均线策略 (支持外部参数配置)
# Dual Moving Average Strategy with External Parameters
# ============================================================
#
#
# 使用方法:
# 1. 在交易助手中选择此指标
# 2. 根据不同币种配置不同参数
# - BTC/USDT: sma_short=5, sma_long=10
# - ETH/USDT: sma_short=5, sma_long=20
#
#
# ============================================================
# === 参数声明 (会在前端表单中显示) ===
+3 -3
View File
@@ -2,12 +2,12 @@
# 多指标组合策略 (均线+RSI+MACD)
# Multi-Indicator Composite Strategy
# ============================================================
#
#
# 使用方法:
# 1. 可配置均线周期、RSI阈值等参数
# 2. 买入条件: RSI超卖 + MACD金叉 + 成交量放大
# 3. 卖出条件: RSI超买 或 MACD死叉
#
#
# ============================================================
# === 参数声明 ===
@@ -78,7 +78,7 @@ buy = ma_golden | rsi_buy # 均线金叉 或 RSI超卖
if use_macd:
buy = buy & (macd > macd_signal) # 需要MACD向上
if use_volume:
buy = buy & volume_up # 需要成交量放大