- 添加 is_scheduled_reconnecting 标志位协调重连逻辑 - 增强定时重连任务的日志前缀便于追踪 - 改进异常处理和资源清理日志 - 优化代码格式和注释
146 lines
4.6 KiB
Plaintext
146 lines
4.6 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "initial_id",
|
|
"metadata": {
|
|
"jupyter": {
|
|
"is_executing": true
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"from operator import index\n",
|
|
"\n",
|
|
"import tushare as ts\n",
|
|
"import pandas as pd\n",
|
|
"import time\n",
|
|
"\n",
|
|
"ts.set_token('3a0741c702ee7e5e5f2bf1f0846bafaafe4e320833240b2a7e4a685f')\n",
|
|
"pro = ts.pro_api()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "f448da220816bf98",
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-07-26T10:23:18.517518100Z",
|
|
"start_time": "2025-04-09T14:57:27.392846Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"数据已经成功存储到index_data.h5文件中\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# 定义四个指数\n",
|
|
"index_list = [\n",
|
|
" # '399300.SZ', \n",
|
|
" '000905.SH', \n",
|
|
" '000852.SH', \n",
|
|
" '399006.SZ'\n",
|
|
" ]\n",
|
|
"\n",
|
|
"# 获取并存储数据\n",
|
|
"all_data = []\n",
|
|
"\n",
|
|
"for ts_code in index_list:\n",
|
|
" df = pro.index_daily(ts_code=ts_code) # 可根据需要设置日期\n",
|
|
" df['ts_code'] = ts_code # 添加ts_code列来区分数据\n",
|
|
" # print(df)\n",
|
|
" all_data.append(df)\n",
|
|
"\n",
|
|
"# 合并所有数据\n",
|
|
"final_df = pd.concat(all_data, ignore_index=True)\n",
|
|
"\n",
|
|
"# 存储到H5文件\n",
|
|
"final_df.to_hdf('/mnt/d/PyProject/NewStock/data/index_data.h5', key='index_data', mode='w')\n",
|
|
"\n",
|
|
"print(\"数据已经成功存储到index_data.h5文件中\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "907f732d3c397bf",
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-07-26T10:23:18.552166300Z",
|
|
"start_time": "2025-04-09T14:57:37.695917Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
" ts_code trade_date close open high low \\\n",
|
|
"0 000905.SH 20260206 8146.4128 8054.2180 8247.2968 8014.6599 \n",
|
|
"1 000905.SH 20260205 8146.1073 8203.0627 8224.7847 8081.4283 \n",
|
|
"2 000905.SH 20260204 8299.0574 8270.8420 8309.8579 8179.3522 \n",
|
|
"3 000905.SH 20260203 8286.7005 8135.8699 8286.7005 8075.3738 \n",
|
|
"4 000905.SH 20260202 8037.0456 8279.7152 8324.4341 8032.3500 \n",
|
|
"... ... ... ... ... ... ... \n",
|
|
"14059 399006.SZ 20100607 1069.4680 1005.0280 1075.2250 1001.7020 \n",
|
|
"14060 399006.SZ 20100604 1027.6810 989.6810 1027.6810 986.5040 \n",
|
|
"14061 399006.SZ 20100603 998.3940 1002.3550 1026.7020 997.7750 \n",
|
|
"14062 399006.SZ 20100602 997.1190 967.6090 997.1190 952.6110 \n",
|
|
"14063 399006.SZ 20100601 973.2330 986.0150 994.7930 948.1180 \n",
|
|
"\n",
|
|
" pre_close change pct_chg vol amount \n",
|
|
"0 8146.1073 0.3055 0.0038 2.186421e+08 4.183734e+08 \n",
|
|
"1 8299.0574 -152.9501 -1.8430 2.318405e+08 4.352777e+08 \n",
|
|
"2 8286.7005 12.3569 0.1491 2.688603e+08 5.018867e+08 \n",
|
|
"3 8037.0456 249.6549 3.1063 2.722271e+08 5.432645e+08 \n",
|
|
"4 8370.5203 -333.4747 -3.9839 2.996460e+08 5.460557e+08 \n",
|
|
"... ... ... ... ... ... \n",
|
|
"14059 1027.6810 41.7870 4.0661 2.655275e+06 9.106095e+06 \n",
|
|
"14060 998.3940 29.2870 2.9334 1.500295e+06 5.269441e+06 \n",
|
|
"14061 997.1190 1.2750 0.1279 1.616805e+06 6.240835e+06 \n",
|
|
"14062 973.2330 23.8860 2.4543 1.074628e+06 4.001206e+06 \n",
|
|
"14063 1000.0000 -26.7670 -2.6767 1.356285e+06 4.924177e+06 \n",
|
|
"\n",
|
|
"[14064 rows x 11 columns]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"h5_filename = '/mnt/d/PyProject/NewStock/data/index_data.h5'\n",
|
|
"key = '/index_data'\n",
|
|
"with pd.HDFStore(h5_filename, mode='r') as store:\n",
|
|
" df = store[key]\n",
|
|
" print(df)\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "stock",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.12.11"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|