Add data retrieval and processing scripts for futures data

- Implemented a function to fetch futures data from the API with error handling and response validation.
- Added example usage for fetching and saving K-line data to CSV.
- Updated CSV files with new data entries for specified date ranges.
- Enhanced the structure of the data retrieval function to include parameters for depth and adjust type.
This commit is contained in:
2025-11-21 20:24:49 +08:00
parent 7ba84a6dd7
commit 800883b6ec
7 changed files with 1954 additions and 164 deletions

View File

@@ -86,9 +86,21 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'ssquant.SQDATA'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mssquant\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mSQDATA\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m TakeData\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'ssquant.SQDATA'"
]
}
],
"source": [
"from ssquant.SQDATA import TakeData"
]
@@ -130,164 +142,9 @@
},
{
"cell_type": "code",
"execution_count": 49,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"头部文件为:--------------------\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>datetime</th>\n",
" <th>symbol</th>\n",
" <th>open</th>\n",
" <th>high</th>\n",
" <th>low</th>\n",
" <th>close</th>\n",
" <th>volume</th>\n",
" <th>amount</th>\n",
" <th>cumulative_openint</th>\n",
" <th>openint</th>\n",
" <th>open_bidp</th>\n",
" <th>open_askp</th>\n",
" <th>close_bidp</th>\n",
" <th>close_askp</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2019-01-02 09:01:00</td>\n",
" <td>rb1905</td>\n",
" <td>3399</td>\n",
" <td>3405</td>\n",
" <td>3389</td>\n",
" <td>3401</td>\n",
" <td>69562</td>\n",
" <td>2362607160</td>\n",
" <td>2383714</td>\n",
" <td>16864</td>\n",
" <td>3399.0</td>\n",
" <td>3400.0</td>\n",
" <td>3400.0</td>\n",
" <td>3401.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2019-01-02 09:02:00</td>\n",
" <td>rb1905</td>\n",
" <td>3401</td>\n",
" <td>3430</td>\n",
" <td>3401</td>\n",
" <td>3410</td>\n",
" <td>88696</td>\n",
" <td>3034283200</td>\n",
" <td>2399530</td>\n",
" <td>-12248</td>\n",
" <td>3401.0</td>\n",
" <td>3402.0</td>\n",
" <td>3409.0</td>\n",
" <td>3410.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2019-01-02 09:03:00</td>\n",
" <td>rb1905</td>\n",
" <td>3409</td>\n",
" <td>3414</td>\n",
" <td>3409</td>\n",
" <td>3412</td>\n",
" <td>22828</td>\n",
" <td>778740580</td>\n",
" <td>2387356</td>\n",
" <td>1180</td>\n",
" <td>3409.0</td>\n",
" <td>3410.0</td>\n",
" <td>3411.0</td>\n",
" <td>3412.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2019-01-02 09:04:00</td>\n",
" <td>rb1905</td>\n",
" <td>3412</td>\n",
" <td>3413</td>\n",
" <td>3403</td>\n",
" <td>3404</td>\n",
" <td>17378</td>\n",
" <td>592413220</td>\n",
" <td>2388158</td>\n",
" <td>54</td>\n",
" <td>3411.0</td>\n",
" <td>3412.0</td>\n",
" <td>3404.0</td>\n",
" <td>3405.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2019-01-02 09:05:00</td>\n",
" <td>rb1905</td>\n",
" <td>3405</td>\n",
" <td>3409</td>\n",
" <td>3405</td>\n",
" <td>3405</td>\n",
" <td>15770</td>\n",
" <td>537276980</td>\n",
" <td>2388190</td>\n",
" <td>1674</td>\n",
" <td>3405.0</td>\n",
" <td>3406.0</td>\n",
" <td>3405.0</td>\n",
" <td>3406.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" datetime symbol open high low close volume amount \\\n",
"0 2019-01-02 09:01:00 rb1905 3399 3405 3389 3401 69562 2362607160 \n",
"1 2019-01-02 09:02:00 rb1905 3401 3430 3401 3410 88696 3034283200 \n",
"2 2019-01-02 09:03:00 rb1905 3409 3414 3409 3412 22828 778740580 \n",
"3 2019-01-02 09:04:00 rb1905 3412 3413 3403 3404 17378 592413220 \n",
"4 2019-01-02 09:05:00 rb1905 3405 3409 3405 3405 15770 537276980 \n",
"\n",
" cumulative_openint openint open_bidp open_askp close_bidp close_askp \n",
"0 2383714 16864 3399.0 3400.0 3400.0 3401.0 \n",
"1 2399530 -12248 3401.0 3402.0 3409.0 3410.0 \n",
"2 2387356 1180 3409.0 3410.0 3411.0 3412.0 \n",
"3 2388158 54 3411.0 3412.0 3404.0 3405.0 \n",
"4 2388190 1674 3405.0 3406.0 3405.0 3406.0 "
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"print('头部文件为:--------------------')\n",
"data.head()"
@@ -363,7 +220,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.13.2"
}
},
"nbformat": 4,