查阅JoinQuant中JQData的使用文档
python代码实现导入JQData,并认证用户身份。认证完毕显示“auth success”后即可使用
from jqdatasdk import *;auth('ID','Password');#ID是申请时所填写的手机号;Password为聚宽官网登录密码# 查询jqdata的调用次数情况surplus_count = get_query_count();print("你剩余的调用次数:", surplus_count);打印结果:
auth success
你剩余的调用次数: {'total': 500000, 'spare': 35444}
#获得所有股票列表df_stocks=get_all_securities("stock");print("所有股票代码列表:\n",df_stocks);打印结果:
所有股票代码列表:
display_name name start_date _date type
000001.XSHE 平安银行 PAYH 1991-04-03 2200-01-01 stock
000002.XSHE 万科A WKA 1991-01-29 2200-01-01 stock
000004.XSHE ST国华 STGH 1990-12-01 2200-01-01 stock
000005.XSHE ST星源 STXY 1990-12-10 2200-01-01 stock
000006.XSHE 深振业A SZYA 1992-04-27 2200-01-01 stock
... ... ... ... ... ...
688799.XSHG 华纳药厂 HNYC 2021-07-13 2200-01-01 stock
688800.XSHG 瑞可达 RKD 2021-07-22 2200-01-01 stock
688819.XSHG 天能股份 TNGF 2021-01-18 2200-01-01 stock
688981.XSHG 中芯国际 ZXGJ 2020-07-16 2200-01-01 stock
689009.XSHG 九号公司 JHGS 2020-10-29 2200-01-01 stock
[4842 rows x 5 columns]
# 获取单只股票的股价历史行情stock_code = '000001.XSHE';now_date = datetime.datetime.now().date();print("当前日期:",now_date);df = get_price(stock_code, start_date=None, _date=now_date, frequency='daily', fields=None, skip_paused=False, fq='pre', count=None, panel=False, fill_paused=True);print("获取到个股(",stock_code,")的历史股票情况:\n", df);打印结果:
当前日期: 2022-05-08
获取到个股( 000001.XSHE )的历史股票情况:
open close high low volume money
2022-01-05 10.16 10.18 10.35 9.92 450000439.0 4.565388e+09
2022-01-06 10.08 10.03 10.42 9.88 340818825.0 3.453446e+09
2022-01-07 9.89 9.84 10.06 9.73 267460942.0 2.634796e+09
2022-01-08 9.85 9.51 9.90 9.47 221459917.0 2.128003e+09
2022-01-09 9.47 9.59 10.09 9.35 394634239.0 3.835378e+09
... ... ... ... ... ... ...
2022-04-27 14.98 15.65 15.65 14.96 149029503.0 2.296799e+09
2022-04-28 15.57 15.65 15.93 15.37 91177187.0 1.426382e+09
2022-04-29 15.69 15.32 15.74 14.97 164501308.0 2.503477e+09
2022-05-05 15.20 15.32 15.45 15.15 79019620.0 1.208735e+09
2022-05-06 15.02 14.96 15.20 14.91 83243182.0 1.250996e+09
[1784 rows x 6 columns]
# 获取所有股票代码stocks =list((df_stocks).index);print("所有股票代码:\n",stocks);打印结果:
所有股票代码:
['000001.XSHE', '000002.XSHE', '000004.XSHE', '000005.XSHE', '000006.XSHE', '000007.XSHE', '000008.XSHE', '000009.XSHE', '000010.XSHE', '000011.XSHE', '000012.XSHE', '000014.XSHE'... ... ... ... ... ... ...
# 获取所有股票代码的历史股价情况--使用for循环count =0;for stock in stocks : count =count+1; # 特意加一个条件退出for循环 if (count >= 5): print("超过5条了,退出!!!"); break; df_stock = get_price(stock_code, start_date=None, _date=now_date, frequency='daily', fields=None, skip_paused=False, fq='pre', count=10, panel=False, fill_paused=True); print("正在获取股票历史行情,股票代码=",stock); print(df_stock); time.sleep(3);打印结果:
正在获取股票历史行情,股票代码= 000001.XSHE
open close high low volume money
2022-04-20 15.81 15.85 16.05 15.70 71655528.0 1.137698e+09
2022-04-21 15.77 15.81 15.98 15.70 70989116.0 1.124664e+09
2022-04-22 15.64 16.06 16.19 15.40 92127408.0 1.468453e+09
2022-04-25 15.67 14.85 15.91 14.78 166448098.0 2.527610e+09
2022-04-26 14.88 14.73 14.98 14.45 98820956.0 1.456930e+09
2022-04-27 14.98 15.65 15.65 14.96 149029503.0 2.296799e+09
2022-04-28 15.57 15.65 15.93 15.37 91177187.0 1.426382e+09
2022-04-29 15.69 15.32 15.74 14.97 164501308.0 2.503477e+09
2022-05-05 15.20 15.32 15.45 15.15 79019620.0 1.208735e+09
2022-05-06 15.02 14.96 15.20 14.91 83243182.0 1.250996e+09
正在获取股票历史行情,股票代码= 000002.XSHE
... ... ... ... ... ... ...
超过5条了,退出!!!
# 获取所有股票代码的历史股价情况--不使用for循环df_temp = get_price(stocks, start_date=None, _date=now_date, frequency='daily', fields=None, skip_paused=False, fq='pre', count=1, panel=False, fill_paused=True);print("所有股票历史行情", df_temp);打印结果:
所有股票历史行情 time code open ... low volume money
0 2022-05-06 002233.XSHE 8.71 ... 8.58 11029400.0 95569870.0
1 2022-05-06 603809.XSHG 15.06 ... 15.06 2567484.0 38961634.0
2 2022-05-06 600205.XSHG NaN ... NaN NaN NaN
3 2022-05-06 002897.XSHE 27.95 ... 26.46 5026501.0 138129266.0
4 2022-05-06 002906.XSHE 31.27 ... 31.00 2643648.0 83371960.0
... ... ... ... ... ... ... ...
4837 2022-05-06 603538.XSHG 45.31 ... 45.18 18267005.0 879567307.0
4838 2022-05-06 688182.XSHG 11.27 ... 11.27 1667005.0 19589407.0
4839 2022-05-06 601598.XSHG 3.77 ... 3.66 45044631.0 167460655.0
4840 2022-05-06 002130.XSHE 5.08 ... 5.03 7799181.0 39705950.0
4841 2022-05-06 603566.XSHG 20.33 ... 20.08 4428201.0 93802047.0
[4842 rows x 8 columns]