# 更新所有股票基本信息
python main.py update-stocks
# 更新沪深300股票基本信息
python main.py update-stocks --index-type hs300
# 更新上证50股票基本信息
python main.py update-stocks --index-type sz50
# 更新中证500股票基本信息
python main.py update-stocks --index-type zz500
# 全量更新沪深300股票K线数据(2023年全年)
python main.py update-kline --index-type hs300 --start-date 2023-01-01 --end-date 2023-12-31
# 增量更新沪深300股票K线数据(只获取最新数据)
python main.py update-kline --index-type hs300 --incremental
# 更新周线数据
python main.py update-kline --index-type hs300 --frequency w --start-date 2023-01-01 --end-date 2023-12-31
# 更新月线数据
python main.py update-kline --index-type hs300 --frequency m --start-date 2023-01-01 --end-date 2023-12-31
# 更新2023年第四季度财务数据
python main.py update-financial --index-type hs300 --year 2023 --quarter 4
# 只更新盈利能力数据
python main.py update-financial --index-type hs300 --year 2023 --quarter 4 --data-types profit
# 更新多种财务数据类型
python main.py update-financial --index-type hs300 --year 2023 --quarter 4 --data-types profit,operation,growth
# 更新2023年业绩数据
python main.py update-performance --index-type hs300 --start-date 2023-01-01 --end-date 2023-12-31
# 只更新业绩快报数据
python main.py update-performance --index-type hs300 --data-types express
python main.py update-industry --index-type hs300
# 更新2023年宏观经济数据
python main.py update-macro --start-date 2023-01-01 --end-date 2023-12-31
# 只更新存款利率数据
python main.py update-macro --data-types deposit_rate
python main.py update-trade-dates --start-date 2023-01-01 --end-date 2023-12-31
python main.py update-adjust-factor --index-type hs300 --start-date 2023-01-01 --end-date 2023-12-31
python main.py update-dividend --index-type hs300 --year 2023
# 更新沪深300所有数据
python main.py update-all --index-type hs300
# 只更新指定类型的数据
python main.py update-all --index-type hs300 --data-types kline,financial,performance
# 每日增量更新K线数据
python main.py update-kline --index-type hs300 --incremental
# 更新交易日历
python main.py update-trade-dates --start-date $(date -d "yesterday" +%Y-%m-%d) --end-date $(date +%Y-%m-%d)
# 更新最新季度财务数据
python main.py update-financial --index-type hs300 --year 2024 --quarter 1
# 补全2020-2023年的历史K线数据
python main.py update-kline --index-type hs300 --start-date 2020-01-01 --end-date 2023-12-31
# 补全历史财务数据
python main.py update-financial --index-type hs300 --year 2020 --quarter 1
python main.py update-financial --index-type hs300 --year 2020 --quarter 2
python main.py update-financial --index-type hs300 --year 2020 --quarter 3
python main.py update-financial --index-type hs300 --year 2020 --quarter 4
# 更新多个指数的数据
python main.py update-all --index-type sz50
python main.py update-all --index-type hs300
python main.py update-all --index-type zz500
from batch_processor import BatchProcessor
from datetime import datetime, timedelta
# 创建批量处理器
with BatchProcessor() as processor:
# 获取股票列表
stock_codes = processor.process_stock_list('hs300')
print(f"获取到 {len(stock_codes)} 只股票")
# 更新K线数据
end_date = datetime.now().strftime('%Y-%m-%d')
start_date = (datetime.now() - timedelta(days=30)).strftime('%Y-%m-%d')
stats = processor.process_kline_data(
stock_codes=stock_codes[:10], # 只处理前10只股票
start_date=start_date,
end_date=end_date,
incremental=True,
max_workers=4
)
print(f"K线数据更新完成: {stats}")
# 更新财务数据
year = datetime.now().strftime('%Y')
quarter = str((datetime.now().month - 1) // 3 + 1)
stats = processor.process_financial_data(
stock_codes=stock_codes[:10],
year=year,
quarter=quarter,
data_types=['profit', 'operation'],
max_workers=4
)
print(f"财务数据更新完成: {stats}")
#!/bin/bash
# 每日数据更新脚本
# 设置日期
TODAY=$(date +%Y-%m-%d)
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
# 更新股票基本信息
python main.py update-stocks --index-type hs300
# 增量更新K线数据
python main.py update-kline --index-type hs300 --incremental
# 更新交易日历
python main.py update-trade-dates --start-date $YESTERDAY --end-date $TODAY
# 更新宏观经济数据(每月1号执行)
if [ $(date +%d) = "01" ]; then
python main.py update-macro --start-date $YESTERDAY --end-date $TODAY
fi
echo "数据更新完成: $TODAY"
# 根据网络状况调整并发数
python main.py update-kline --index-type hs300 --max-workers 8
# 对于大量数据,可以分批处理
python main.py update-kline --index-type all --start-date 2020-01-01 --end-date 2020-12-31
python main.py update-kline --index-type all --start-date 2021-01-01 --end-date 2021-12-31
python main.py update-kline --index-type all --start-date 2022-01-01 --end-date 2022-12-31
# 优先使用增量更新
python main.py update-kline --index-type hs300 --incremental
# 如果某些股票数据获取失败,可以重新运行
python main.py update-kline --index-type hs300 --incremental
-- 查询股票基本信息
SELECT * FROM stock_basic WHERE code_name LIKE '%银行%';
-- 查询K线数据
SELECT * FROM stock_kline
WHERE code = 'sh.600000'
AND date >= '2023-01-01'
ORDER BY date DESC;
-- 查询财务数据
SELECT * FROM stock_profit
WHERE code = 'sh.600000'
AND statDate >= '2023-01-01'
ORDER BY statDate DESC;
-- 统计各表数据量
SELECT
'stock_basic' as table_name, COUNT(*) as count FROM stock_basic
UNION ALL
SELECT 'stock_kline', COUNT(*) FROM stock_kline
UNION ALL
SELECT 'stock_profit', COUNT(*) FROM stock_profit;
- 数据更新频率: BaoStock的数据通常在交易日17:30后更新
- 网络稳定性: 建议在网络稳定的环境下运行
- 数据库备份: 定期备份重要数据
- 监控日志: 定期检查日志文件,及时处理错误
- 资源使用: 根据服务器性能调整并发数和批处理大小