{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "from ssquant.SQDATA import TakeData\n", "\n", "#注意首先需要pip install ssquant\n", "#否则链接不到数据库\n", "#输入俱乐部的账号密码即可调用,注意保密。\n", "#目前数据是2019年1月-至今\n", "#每日下午收盘后3点30分录入当天数据。\n", "#有任何疑问可以再群里提出,或者私信我(慕金龙)\n", "#官网: quant789.com\n", "#公众号:松鼠Quant\n", "#客服微信: viquant01\n", "\n", "#只能调取分钟及以上数据,tick数据每月底更新到百度网盘下载\n", "\n", "'''\n", "获取数据-\n", "品种:symbol,不区分大小写\n", "起始时间:start_date,\n", "结束时间:end_date(包含当天),\n", "周期kline_period:1M..5M..NM(分钟),1D(天),1W(周),1Y(月)\n", "复权adjust_type:0(不复权)1(后复权)\n", "注意:\n", "1.请正确输入账号密码\n", "2.不要挂代理访问数据库\n", "3.暂时没有股指数据,下个月补齐。\n", "'''\n", " \n", "# username='俱乐部账号' password='密码'\n", "client = TakeData(username='77777@qq.com', password='7777')\n", "data = client.get_data(\n", " symbol='rb888',\n", " start_date='2023-01-02',\n", " end_date='2024-01-03',\n", " kline_period='60M',\n", " adjust_type=1\n", ")\n", "print(data)\n", "\n", "\n", "\n", "'''\n", "datetime:时间,\n", "\n", "symbol:品种,\n", "\n", "open:开盘价,\n", "\n", "high:最高价,\n", "\n", "low:最低价,\n", "\n", "close:收盘价,\n", "\n", "volume:成交量(单bar),\n", "\n", "amount:成交金额(单bar),\n", "\n", "openint:持仓量(单bar),\n", "\n", "cumulative_openint:累计持仓量,\n", "\n", "open_bidp , open_askp: K线第一个价格的买一价格和卖一价格\n", "\n", "close_bidp , close_askp: K线最后一个价格的买一价格和卖一价格\n", "\n", "\n", " datetime symbol open high low close volume amount cumulative_openint openint open_bidp open_askp close_bidp close_askp\n", "0 2023-01-03 10:00:00 rb2305 4081.0 4081.0 4016.0 4037.0 737537 29782187220 1883481 -48415 4081.0 4084.0 4037.0 4038.0\n", "1 2023-01-03 11:00:00 rb2305 4038.0 4056.0 4037.0 4042.0 158548 6415696920 1887716 4235 4037.0 4038.0 4042.0 4044.0\n", "2 2023-01-03 12:00:00 rb2305 4044.0 4054.0 4037.0 4051.0 67448 2728130300 1890125 2409 4043.0 4044.0 4050.0 4051.0\n", "3 2023-01-03 14:00:00 rb2305 4055.0 4065.0 4045.0 4058.0 110181 4469698600 1895841 5723 4050.0 4051.0 4058.0 4059.0\n", "4 2023-01-03 15:00:00 rb2305 4059.0 4074.0 4056.0 4063.0 167932 6824213940 1882723 -13125 4058.0 4059.0 4062.0 4063.0\n", "... ... ... ... ... ... ... ... ... ... ... ... ... ... ...\n", "1689 2024-01-03 12:00:00 rb2405 4055.0 4057.0 4044.0 4049.0 79745 3229361570 1597387 -6515 4054.0 4055.0 4049.0 4050.0\n", "1690 2024-01-03 14:00:00 rb2405 4050.0 4056.0 4046.0 4049.0 55040 2229498750 1598566 1179 4050.0 4051.0 4049.0 4050.0\n", "1691 2024-01-03 15:00:00 rb2405 4050.0 4064.0 4048.0 4055.0 148845 6038835190 1583796 -14770 4049.0 4050.0 4055.0 4056.0\n", "1692 2024-01-03 22:00:00 rb2405 4054.0 4054.0 4040.0 4049.0 181753 7354584770 1582419 990 4053.0 4054.0 4048.0 4049.0\n", "1693 2024-01-03 23:00:00 rb2405 4049.0 4057.0 4042.0 4049.0 104712 4240341050 1574287 -8132 4048.0 4049.0 4049.0 4050.0" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from ssquant.SQDATA import TakeData" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "out_path = r'D:/data'\n", "symbol_name = 'rb888' #主力连续888 次主力合约777\n", "time_period = '1M'\n", "start_time = '2000-01-01'\n", "end_time = '2019-01-31'\n", "adjust_k = 'Faj' #Naj:Non adjust,Faj:Forward adjust,后复权\n", "\n", "if adjust_k == 'Naj':\n", " adjust_tmp = 0\n", "elif adjust_k == 'Faj':\n", " adjust_tmp = 1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "client = TakeData(username='240884432@qq.com', password='Zj123!@#')\n", "data = client.get_data(\n", " symbol=symbol_name,\n", " start_date=start_time,\n", " end_date=end_time,\n", " kline_period=time_period,\n", " adjust_type= adjust_tmp\n", ")" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "头部文件为:--------------------\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
datetimesymbolopenhighlowclosevolumeamountcumulative_openintopenintopen_bidpopen_askpclose_bidpclose_askp
02019-01-02 09:01:00rb190533993405338934016956223626071602383714168643399.03400.03400.03401.0
12019-01-02 09:02:00rb190534013430340134108869630342832002399530-122483401.03402.03409.03410.0
22019-01-02 09:03:00rb1905340934143409341222828778740580238735611803409.03410.03411.03412.0
32019-01-02 09:04:00rb19053412341334033404173785924132202388158543411.03412.03404.03405.0
42019-01-02 09:05:00rb1905340534093405340515770537276980238819016743405.03406.03405.03406.0
\n", "
" ], "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" } ], "source": [ "print('头部文件为:--------------------')\n", "data.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from datetime import datetime\n", " \n", "# 假设你有一个字符串,表示时间,格式为 'YYYY-MM-DD HH:MM:SS'\n", "real_start_time = data.iloc[0,0]\n", " \n", "# 使用datetime.strptime将字符串转换为时间\n", "time_obj = datetime.strptime(real_start_time, '%Y-%m-%d %H:%M:%S')\n", " \n", "# 获取年月日\n", "year = time_obj.year\n", "month = time_obj.month\n", "day = time_obj.day\n", " \n", "print(f'年: {year}, 月: {month}, 日: {day}')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('尾部文件为:--------------------')\n", "data.tail()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import datetime\n", "real_start_time = pd.to_datetime(data.iloc[0,0]).date().strftime('%Y-%m-%d')\n", "real_end_time = pd.to_datetime(data.iloc[-1,0]).date().strftime('%Y-%m-%d')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data.to_csv('%s/%s_%s_%s(%s_%s).csv'%(out_path,symbol_name,time_period,adjust_k,real_start_time,real_end_time), index=False)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.10.9" } }, "nbformat": 4, "nbformat_minor": 2 }