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:
@@ -0,0 +1,3 @@
|
||||
datetime,symbol,open,high,low,close,volume,turnover,open_interest
|
||||
2025-10-09 09:30:00,IM2512,7444.0,7445.2,7443.8,7445.2,406,604503760,-176
|
||||
2025-10-09 09:45:00,IM2512,7448.0,7497.8,7430.8,7482.6,20461,30561185000,-6689
|
||||
|
@@ -0,0 +1,37 @@
|
||||
datetime,symbol,open,high,low,close,volume,turnover,open_interest
|
||||
2025/10/9 9:30:00,IM2512,7444,7445.2,7443.8,7445.2,406,604503760,-176
|
||||
2025/10/9 9:45:00,IM2512,7448,7497.8,7430.8,7482.6,20461,30561185000,-6689
|
||||
2025/10/9 10:00:00,IM2512,7482.6,7486.6,7413.2,7438.2,16226,24136810440,-3489
|
||||
2025/10/9 10:15:00,IM2512,7436.6,7495.4,7425,7485,11496,17154464040,-1823
|
||||
2025/10/9 10:30:00,IM2512,7485.4,7490,7472.2,7488.6,7543,11285654240,-324
|
||||
2025/10/9 10:45:00,IM2512,7500,7517.8,7481.4,7508.6,9391,14084729600,584
|
||||
2025/10/9 11:00:00,IM2512,7508,7519,7484,7497.6,7377,11069550680,-184
|
||||
2025/10/9 11:15:00,IM2512,7498.2,7512.6,7493.2,7509.4,5153,7733800280,330
|
||||
2025/10/9 11:30:00,IM2512,7511.8,7515,7491.8,7497.8,4425,6640375520,639
|
||||
2025/10/9 13:00:00,IM2512,7496.2,7496.8,7496.2,7496.8,32,47974960,-1
|
||||
2025/10/9 13:15:00,IM2512,7497.2,7499.2,7475.2,7485.8,6500,9733899920,589
|
||||
2025/10/9 13:30:00,IM2512,7486,7490.4,7466.6,7486,5213,7795326120,634
|
||||
2025/10/9 13:45:00,IM2512,7487.4,7494.4,7477,7477,3671,5497097120,740
|
||||
2025/10/9 14:00:00,IM2512,7476.2,7489,7456.4,7486.2,7696,11501011000,1633
|
||||
2025/10/9 14:15:00,IM2512,7485,7502.6,7477,7481.8,5525,8276203640,1217
|
||||
2025/10/9 14:30:00,IM2512,7481,7492,7447.4,7455.8,7169,10703287880,1738
|
||||
2025/10/9 14:45:00,IM2512,7455.8,7468,7454.2,7461.6,4891,7299102080,1399
|
||||
2025/10/9 15:00:00,IM2512,7461,7468,7449.6,7449.6,7203,10744653160,1766
|
||||
2025/10/10 9:30:00,IM2512,7415,7417.6,7415,7417.4,595,882483920,-241
|
||||
2025/10/10 9:45:00,IM2512,7416.8,7433,7353.2,7353.2,26824,39698311640,-12378
|
||||
2025/10/10 10:00:00,IM2512,7352.6,7379.8,7339,7359.8,18742,27579709040,-3461
|
||||
2025/10/10 10:15:00,IM2512,7357.8,7375.6,7340,7343,9092,13374526160,-296
|
||||
2025/10/10 10:30:00,IM2512,7343.8,7373,7331.6,7373,8344,12267357720,263
|
||||
2025/10/10 10:45:00,IM2512,7374,7397.8,7373,7374.4,8100,11962701680,689
|
||||
2025/10/10 11:00:00,IM2512,7373.8,7391.6,7369.6,7375.8,4499,6640018080,130
|
||||
2025/10/10 11:15:00,IM2512,7375.6,7379,7357.4,7361.2,5339,7867726520,783
|
||||
2025/10/10 11:30:00,IM2512,7361.6,7367.2,7337,7349.2,6178,9084385760,679
|
||||
2025/10/10 13:00:00,IM2512,7350.8,7350.8,7349,7349,37,54391480,7
|
||||
2025/10/10 13:15:00,IM2512,7349,7366.6,7341.8,7361.2,5066,7453994640,1220
|
||||
2025/10/10 13:30:00,IM2512,7360.8,7365,7349.8,7358.6,3472,5108998600,1031
|
||||
2025/10/10 13:45:00,IM2512,7358,7371.4,7335,7345.4,6372,9368157960,1088
|
||||
2025/10/10 14:00:00,IM2512,7346.4,7380.6,7342,7380.6,7364,10842634240,2320
|
||||
2025/10/10 14:15:00,IM2512,7381.8,7386.8,7340.6,7340.6,7534,11087884440,2262
|
||||
2025/10/10 14:30:00,IM2512,7341.4,7353,7330.2,7347.6,6980,10249484440,2363
|
||||
2025/10/10 14:45:00,IM2512,7348.4,7364.4,7335.4,7342.4,5690,8364008080,2237
|
||||
2025/10/10 15:00:00,IM2512,7342.4,7348.2,7327.2,7340.4,9841,14443336560,2355
|
||||
|
@@ -0,0 +1,37 @@
|
||||
datetime,symbol,open,high,low,close,volume,amount,openint,cumulative_openint,open_askp,open_bidp,close_askp,close_bidp,开仓,平仓,多开,空开,多平,空平,双开,双平,双换,B,S,未知
|
||||
2025-10-09 09:30:00,IM2512,7444.0,7445.2,7443.8,7445.2,406,604503760,-176,183346,7445.0,7443.2,7448.0,7447.2,0,406,0,0,119,230,0,57,0,230,119,0
|
||||
2025-10-09 09:45:00,IM2512,7448.0,7497.8,7430.8,7482.6,20461,30561185000,-6689,176657,7448.0,7447.2,7484.0,7482.6,2468,16620,1079,932,6738,7334,457,2548,261,8413,7670,1112
|
||||
2025-10-09 10:00:00,IM2512,7482.6,7486.6,7413.2,7438.2,16226,24136810440,-3489,173168,7484.8,7482.6,7438.0,7435.6,3309,11270,1281,1356,4765,4298,672,2207,375,5579,6121,1272
|
||||
2025-10-09 10:15:00,IM2512,7436.6,7495.4,7425.0,7485.0,11496,17154464040,-1823,171345,7436.8,7435.8,7486.2,7485.6,3312,6782,1154,1312,2567,2905,846,1310,322,4059,3879,1080
|
||||
2025-10-09 10:30:00,IM2512,7485.4,7490.0,7472.2,7488.6,7543,11285654240,-324,171019,7486.4,7485.0,7488.8,7488.6,2875,3611,1184,1271,1454,1468,420,689,218,2652,2725,839
|
||||
2025-10-09 10:45:00,IM2512,7500.0,7517.8,7481.4,7508.6,9391,14084729600,584,171653,7500.0,7498.8,7509.0,7508.2,4459,3507,1930,1822,1420,1590,707,497,389,3520,3242,1036
|
||||
2025-10-09 11:00:00,IM2512,7508.0,7519.0,7484.0,7497.6,7377,11069550680,-184,171469,7508.8,7508.0,7498.0,7497.6,2836,3227,1194,1269,1396,1220,373,611,272,2414,2665,1042
|
||||
2025-10-09 11:15:00,IM2512,7498.2,7512.6,7493.2,7509.4,5153,7733800280,330,171795,7498.8,7498.2,7510.0,7509.4,2393,1709,1180,899,626,763,314,320,224,1943,1525,827
|
||||
2025-10-09 11:30:00,IM2512,7511.8,7515.0,7491.8,7497.8,4425,6640375520,639,172438,7511.8,7510.8,7497.8,7496.2,2351,1271,991,1046,554,554,314,163,184,1545,1600,619
|
||||
2025-10-09 13:00:00,IM2512,7496.2,7496.8,7496.2,7496.8,32,47974960,-1,172437,7496.2,7495.6,7497.4,7496.8,0,8,0,0,8,0,0,0,0,0,8,24
|
||||
2025-10-09 13:15:00,IM2512,7497.2,7499.2,7475.2,7485.8,6500,9733899920,589,173026,7498.6,7497.4,7486.4,7486.0,3293,2109,1341,1403,820,868,549,421,259,2209,2223,839
|
||||
2025-10-09 13:30:00,IM2512,7486.0,7490.4,7466.6,7486.0,5213,7795326120,634,173660,7486.0,7485.4,7486.6,7486.0,2802,1490,1049,1349,604,712,404,174,156,1761,1953,765
|
||||
2025-10-09 13:45:00,IM2512,7487.4,7494.4,7477.0,7477.0,3671,5497097120,740,174408,7488.0,7487.6,7476.8,7476.2,2076,864,783,958,361,366,335,137,132,1149,1319,599
|
||||
2025-10-09 14:00:00,IM2512,7476.2,7489.0,7456.4,7486.2,7696,11501011000,1633,176036,7476.8,7476.2,7486.2,7485.6,4641,1882,1691,2203,647,891,747,344,194,2582,2850,979
|
||||
2025-10-09 14:15:00,IM2512,7485.0,7502.6,7477.0,7481.8,5525,8276203640,1217,177254,7485.6,7485.2,7481.2,7481.0,3369,1164,1338,1537,476,489,494,199,191,1827,2013,801
|
||||
2025-10-09 14:30:00,IM2512,7481.0,7492.0,7447.4,7455.8,7169,10703287880,1738,178996,7481.0,7480.8,7456.4,7455.8,4537,1580,1855,2105,789,530,577,261,153,2385,2894,899
|
||||
2025-10-09 14:45:00,IM2512,7455.8,7468.0,7454.2,7461.6,4891,7299102080,1399,180390,7456.0,7454.6,7462.0,7460.4,3146,881,1400,1315,317,483,431,81,144,1883,1632,720
|
||||
2025-10-09 15:00:00,IM2512,7461.0,7468.0,7449.6,7449.6,7203,10744653160,1766,182161,7461.8,7461.2,7450.6,7449.6,4603,1573,1749,2375,843,578,479,152,114,2327,3218,913
|
||||
2025-10-10 09:30:00,IM2512,7415.0,7417.6,7415.0,7417.4,595,882483920,-241,181920,7417.4,7415.0,7416.8,7412.0,91,504,91,0,245,259,0,0,0,350,245,0
|
||||
2025-10-10 09:45:00,IM2512,7416.8,7433.0,7353.2,7353.2,26824,39698311640,-12378,169542,7416.8,7415.6,7353.4,7353.2,1483,24554,602,488,11019,9562,393,3973,243,10164,11507,544
|
||||
2025-10-10 10:00:00,IM2512,7352.6,7379.8,7339.0,7359.8,18742,27579709040,-3461,166081,7352.4,7352.0,7359.4,7358.0,4447,12800,1570,1977,5331,5334,900,2135,310,6904,7308,1185
|
||||
2025-10-10 10:15:00,IM2512,7357.8,7375.6,7340.0,7343.0,9092,13374526160,-296,165785,7357.8,7357.0,7344.0,7343.0,3853,3967,1580,1685,1472,1646,588,849,321,3226,3157,951
|
||||
2025-10-10 10:30:00,IM2512,7343.8,7373.0,7331.6,7373.0,8344,12267357720,263,166048,7343.8,7342.6,7373.4,7373.0,3821,3190,1545,1627,1183,1435,649,572,333,2980,2810,1000
|
||||
2025-10-10 10:45:00,IM2512,7374.0,7397.8,7373.0,7374.4,8100,11962701680,689,166772,7374.4,7374.0,7374.2,7373.4,4123,2630,1941,1626,1072,1149,556,409,237,3090,2698,1110
|
||||
2025-10-10 11:00:00,IM2512,7373.8,7391.6,7369.6,7375.8,4499,6640018080,130,166902,7374.6,7374.4,7376.4,7375.6,2022,1627,927,866,671,684,229,272,179,1611,1537,671
|
||||
2025-10-10 11:15:00,IM2512,7375.6,7379.0,7357.4,7361.2,5339,7867726520,783,167685,7375.4,7375.2,7363.0,7361.2,2806,1619,1097,1319,821,518,390,280,183,1615,2140,731
|
||||
2025-10-10 11:30:00,IM2512,7361.6,7367.2,7337.0,7349.2,6178,9084385760,679,168364,7362.8,7361.4,7350.6,7349.0,3068,1943,1295,1218,913,676,555,354,289,1971,2131,878
|
||||
2025-10-10 13:00:00,IM2512,7350.8,7350.8,7349.0,7349.0,37,54391480,7,168371,7350.2,7349.2,7350.6,7349.0,12,25,12,0,25,0,0,0,0,12,25,0
|
||||
2025-10-10 13:15:00,IM2512,7349.0,7366.6,7341.8,7361.2,5066,7453994640,1220,169591,7352.2,7349.0,7362.0,7361.2,3031,1103,1280,1195,415,507,556,181,193,1787,1610,739
|
||||
2025-10-10 13:30:00,IM2512,7360.8,7365.0,7349.8,7358.6,3472,5108998600,1031,170622,7361.2,7360.8,7359.4,7358.6,2205,560,1068,785,245,206,352,109,167,1274,1030,540
|
||||
2025-10-10 13:45:00,IM2512,7358.0,7371.4,7335.0,7345.4,6372,9368157960,1088,171730,7358.0,7357.4,7346.4,7345.2,3566,1729,1379,1719,798,697,468,234,205,2076,2517,872
|
||||
2025-10-10 14:00:00,IM2512,7346.4,7380.6,7342.0,7380.6,7364,10842634240,2320,174050,7346.8,7345.6,7380.8,7380.6,5174,1160,2230,2152,413,612,792,135,217,2842,2565,813
|
||||
2025-10-10 14:15:00,IM2512,7381.8,7386.8,7340.6,7340.6,7534,11087884440,2262,176312,7382.6,7381.8,7341.4,7340.4,5204,1365,2031,2125,638,479,1048,248,172,2510,2763,793
|
||||
2025-10-10 14:30:00,IM2512,7341.4,7353.0,7330.2,7347.6,6980,10249484440,2363,178675,7341.8,7340.4,7348.4,7347.6,5028,1122,2187,2004,360,632,837,130,131,2819,2364,699
|
||||
2025-10-10 14:45:00,IM2512,7348.4,7364.4,7335.4,7342.4,5690,8364008080,2237,180909,7349.8,7348.4,7343.6,7342.4,4179,659,1603,1952,338,258,624,63,163,1861,2290,689
|
||||
2025-10-10 15:00:00,IM2512,7342.4,7348.2,7327.2,7340.4,9841,14443336560,2355,183267,7344.0,7343.2,7341.8,7340.6,6345,2260,2637,2915,1237,836,793,187,154,3473,4152,1082
|
||||
|
@@ -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,
|
||||
|
||||
109
2.数据下载与处理/ssquant_download/专属数据库请求数据API示例.py
Normal file
109
2.数据下载与处理/ssquant_download/专属数据库请求数据API示例.py
Normal file
@@ -0,0 +1,109 @@
|
||||
import requests
|
||||
import pandas as pd
|
||||
from datetime import datetime, timedelta
|
||||
from io import StringIO
|
||||
|
||||
def get_futures_data(symbol, start_date, end_date, kline_period='1m', adjust_type='0', depth='no'):
|
||||
"""
|
||||
获取期货数据
|
||||
"""
|
||||
# 构建请求参数
|
||||
params = {
|
||||
'username': username,
|
||||
'password': password,
|
||||
'symbol': symbol,
|
||||
'start_date': start_date,
|
||||
'end_date': end_date,
|
||||
'kline_period': kline_period,
|
||||
'adjust_type': adjust_type
|
||||
}
|
||||
|
||||
if depth:
|
||||
params['Depth'] = depth
|
||||
|
||||
print("请求参数:", params) # 打印请求参数,便于调试
|
||||
|
||||
try:
|
||||
# 发送请求,设置超时时间为30秒
|
||||
response = requests.get(base_url, params=params, timeout=300)
|
||||
|
||||
# 检查响应状态
|
||||
if response.status_code == 200:
|
||||
# 检查响应是否为JSON格式
|
||||
if 'application/json' in response.headers.get('Content-Type', ''):
|
||||
data = pd.read_json(StringIO(response.text), orient='records')
|
||||
data=data.reset_index()
|
||||
#列名排序
|
||||
if depth=='yes':
|
||||
columns=['datetime','symbol','open','high','low','close','volume','amount','openint','cumulative_openint','open_askp','open_bidp','close_askp','close_bidp','开仓','平仓','多开','空开','多平','空平','双开','双平','双换','B','S','未知']
|
||||
else:
|
||||
columns=['datetime','symbol','open','high','low','close','volume','amount','openint','cumulative_openint','open_askp','open_bidp','close_askp','close_bidp']
|
||||
# 重新排列列名
|
||||
data = data.reindex(columns=columns)
|
||||
data['datetime'] = pd.to_datetime(data['datetime'])
|
||||
# 更改时间显示的格式,例如 "YYYY-MM-DD HH:MM:SS"
|
||||
# 将 UTC 时间转换为本地时区,例如 'Asia/Shanghai'
|
||||
data['datetime'] = data['datetime'].dt.tz_convert('Asia/Shanghai')
|
||||
data['datetime'] = data['datetime'].dt.strftime('%Y-%m-%d %H:%M:%S')
|
||||
return data
|
||||
else:
|
||||
print("响应不是JSON格式:", response.text[:1000])
|
||||
return None
|
||||
elif response.status_code == 401:
|
||||
print("认证失败:用户名和密码不能为空")
|
||||
return None
|
||||
elif response.status_code == 402:
|
||||
print("认证失败:账号不存在,请检查账号后重新输入......如还有问题联系管理员微信:viquant01")
|
||||
return None
|
||||
elif response.status_code == 405:
|
||||
print("认证失败:账号已过期,请联系管理员微信:viquant01")
|
||||
return None
|
||||
elif response.status_code == 406:
|
||||
print("认证失败:密码错误,请检查密码后重新输入......如还有问题联系管理员微信:viquant01")
|
||||
return None
|
||||
else:
|
||||
print(f"请求失败,状态码:{response.status_code}")
|
||||
print(f"错误信息:{response.json().get('error', '未知错误')}")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
print(f"发生错误:{e}")
|
||||
print("请求URL:", response.url)
|
||||
print("响应内容:", response.text[:1000]) # 打印前1000个字符
|
||||
return None
|
||||
|
||||
# 使用示例
|
||||
if __name__ == "__main__":
|
||||
# API配置
|
||||
base_url = 'http://kanpan789.com:8086/ftdata'
|
||||
# 用户认证信息
|
||||
username = '240884432@qq.com' # 替换为你的手机号或者邮箱
|
||||
password = 'Zj123!@#' # 替换为你的密码
|
||||
# 示例参数
|
||||
symbol = "IM888" #
|
||||
start_date = "2025-10-01" #start_date : 开始时间
|
||||
end_date = "2025-10-10" #end_date(包含当天):结束时间
|
||||
kline_period="15M" #周期:1M..5M..NM(分钟),1D(天),1W(周),1Y(月)
|
||||
adjust_type= 0 #复权开关 :0(不复权)1(后复权)
|
||||
depth='yes' # 获取交易数据统计: yes(获取),no(不获取)
|
||||
|
||||
# 获取K线数据
|
||||
df_data = get_futures_data(
|
||||
symbol=symbol,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
kline_period=kline_period,
|
||||
adjust_type=adjust_type,
|
||||
depth=depth
|
||||
)
|
||||
|
||||
if df_data is not None:
|
||||
print("\nK线数据示例:")
|
||||
print(df_data)
|
||||
print(f"\n数据条数:{len(df_data)}")
|
||||
|
||||
# 保存到CSV文件(可选)
|
||||
csv_filename = f"{symbol}_{start_date}_{end_date}_1m.csv"
|
||||
df_data.to_csv(csv_filename, index=False)
|
||||
print(f"\n数据已保存到文件:{csv_filename}")
|
||||
|
||||
@@ -88,10 +88,22 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": 1,
|
||||
"id": "65b4b7aa",
|
||||
"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[1]\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[32m 2\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpandas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpd\u001b[39;00m\n",
|
||||
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'ssquant.SQDATA'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from ssquant.SQDATA import TakeData\n",
|
||||
"import pandas as pd"
|
||||
@@ -227,7 +239,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
@@ -241,7 +253,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.9"
|
||||
"version": "3.13.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
1735
temp/dingdanliu_nb_option.py
Normal file
1735
temp/dingdanliu_nb_option.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user