QTrade/check_tables.py
cuizhan 43ab91b44d 重构数据系统:ta-lib指标、RSI多周期、数据库精度优化、表结构统一
核心改进:
- 指标计算:全部切换为ta-lib实现(MACD/KDJ/BOLL)
- RSI指标:新增多周期RSI(6/12/24),列名rsi_fast/mid/slow
- 数据精度:数据库DECIMAL(10,3)支持ETF 3位小数,下载器round(x,3)
- 表结构:所有表使用(symbol,timestamp)复合主键,移除id自增
- 表命名:统一为indicators_{period}_{indicator}格式,删除42个旧表
- 自动计算:DataProvider下载后自动计算并保存指标
- 列名规范:macd_dif/dea/histogram, kdj_k/d/j, boll_upper/mid/lower
- KlineReader:保留timestamp和symbol列供指标计算使用

已验证:1m周期2400+条数据,所有指标正常计算保存
2025-12-17 22:58:22 +08:00

55 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""检查数据库中的所有表"""
from src.database_manager.db_manager import DatabaseManager
def main():
db = DatabaseManager()
database = "qtrade_backtest"
# 获取所有表名
tables = db.list_tables(database)
# 分类统计
klines = []
indicators = []
business = []
old_format = [] # 旧格式的指标表(indicator_period 格式)
for table_name in tables:
if table_name.startswith("klines_"):
klines.append(table_name)
elif table_name.startswith("indicators_"):
indicators.append(table_name)
elif "_" in table_name and any(
table_name.startswith(ind)
for ind in ["macd", "kdj", "boll", "rsi", "ma", "ema"]
):
old_format.append(table_name)
else:
business.append(table_name)
print(f"总表数: {len(tables)}")
print(f"\n=== K线表 ({len(klines)}) ===")
for t in sorted(klines):
print(f" {t}")
print(f"\n=== 指标表(新格式: indicators_period_indicator)({len(indicators)}) ===")
for t in sorted(indicators):
print(f" {t}")
print(f"\n=== 旧格式指标表(indicator_period)({len(old_format)}) ===")
if old_format:
for t in sorted(old_format):
print(f" {t}")
else:
print(" (无)")
print(f"\n=== 业务表 ({len(business)}) ===")
for t in sorted(business):
print(f" {t}")
if __name__ == "__main__":
main()