This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
数据表分表完成总结
完成状态: ✅ 全部完成
股票数据表分表
日线分表 (3张表)
表名
用途
状态
stock_klines_1d_base
基础K线数据 (OHLCV)
✅
stock_klines_1d_quote
行情指标 (均线/MACD/涨跌幅)
✅
stock_klines_1d_finance
财务数据 (市值/股本/利润)
✅
分钟线 (2张表)
表名
用途
状态
stock_klines_1m
1分钟线
✅
stock_klines_5m
5分钟线
✅
实时数据 (1张表)
表名
用途
状态
stock_realtime_quotes
实时行情快照
✅
期货数据表分表
日线分表 (2张表)
表名
用途
状态
futures_klines_1d_base
基础K线数据 (OHLCV+持仓量)
✅
futures_klines_1d_quote
行情指标 (均线/MACD/持仓变化)
✅
分钟线 (2张表)
表名
用途
状态
futures_klines_1m_base
1分钟基础线
✅
futures_klines_5m_base
5分钟基础线
✅
实时数据 (1张表)
表名
用途
状态
futures_realtime_quotes
实时行情快照
✅
代码文件
模型定义
app/repositories/models.py - 所有分表模型定义
数据仓库
app/repositories/stock_repository_v2.py - 股票分表仓库
app/repositories/futures_repository_v2.py - 期货分表仓库
创建脚本
scripts/create_split_tables.py - 创建所有分表
scripts/add_stock_split_tables.py - 添加股票分表
scripts/fix_models.py - 添加期货分表
使用方法
1. 创建分表
python scripts/create_split_tables.py
2. 股票数据操作
from app.repositories.stock_repository_v2 import StockRepositoryV2
from app.repositories.database import SessionLocal
from app.models import Frequency
db = SessionLocal ()
repo = StockRepositoryV2 ( db )
# 查询基础数据
base_data = repo . get_klines_base (
symbol = "600519.SH" ,
freq = Frequency . FREQ_1D ,
start = datetime ( 2024 , 1 , 1 ),
end = datetime ( 2024 , 3 , 1 )
)
# 查询行情指标
quote_data = repo . get_klines_quote (
symbol = "600519.SH" ,
start_date = "2024-01-01" ,
end_date = "2024-03-01"
)
# 查询财务数据
finance_data = repo . get_klines_finance (
symbol = "600519.SH" ,
start_date = "2024-01-01" ,
end_date = "2024-03-01"
)
3. 期货数据操作
from app.repositories.futures_repository_v2 import FuturesRepositoryV2
db = SessionLocal ()
repo = FuturesRepositoryV2 ( db )
# 查询基础数据
base_data = repo . get_klines_base (
symbol = "RB2410.SH" ,
freq = Frequency . FREQ_1D ,
start = datetime ( 2024 , 1 , 1 ),
end = datetime ( 2024 , 3 , 1 )
)
# 查询行情指标
quote_data = repo . get_klines_quote (
symbol = "RB2410.SH" ,
start_date = "2024-01-01" ,
end_date = "2024-03-01"
)
分表设计优势
查询性能 : 只需基础数据时, 只查询轻量的base表
更新解耦 :
基础数据: 每日更新
行情指标: 计算后更新
财务数据: 财报季更新
扩展性 : 新增指标只需修改quote表
存储优化 : 冷热数据分离
总表数统计
类别
表数量
股票分表
6张
期货分表
5张
总计
11张