QUANTAXIS的数据获取部分

QUANTAXIS的数据获取部分

这篇文章介绍了QA的数据获取部分。

从网络获取

股票/日线

下面的这些代码会得到一个数据框。
不过设置复权之后运行结果会显示:
CURRENTLY NOT SUPPORT REALTIME FUQUAN
似乎还不支持实时复权。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 股票/日线
import QUANTAXIS as QA
QA.QA_util_log_info('日线数据')
QA.QA_util_log_info('不复权')
data = QA.QAFetch.QATdx.QA_fetch_get_stock_day('000001', '2018-01-01', '2018-09-24')

QA.QA_util_log_info('前复权')
data = QA.QAFetch.QATdx.QA_fetch_get_stock_day('000001', '2018-01-01', '2018-09-24', '01')

QA.QA_util_log_info('后复权')
data = QA.QAFetch.QATdx.QA_fetch_get_stock_day('000001', '2018-01-01', '2018-09-24', '02')

QA.QA_util_log_info('定点前复权')
data = QA.QAFetch.QATdx.QA_fetch_get_stock_day('000001', '2018-01-01', '2018-09-24', '03')

QA.QA_util_log_info('定点后复权')
data = QA.QAFetch.QATdx.QA_fetch_get_stock_day('000001', '2018-01-01', '2018-09-24', '04')

股票/分钟线

1
2
3
QA.QA_util_log_info('分钟线')
QA.QA_util_log_info('1min')
data = QA.QAFetch.QATdx.QA_fetch_get_stock_min('000001', '2018-01-01', '2018-09-24', '1min')

除此之外还可以选择5min/15min/30min/60min。

股票/权息数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
QA.QA_util_log_info('除权除息')
data = QA.QAFetch.QATdx.QA_fetch_get_stock_xdxr('000001')
data.head()
QUANTAXIS>> 除权除息
Out[9]:
category name fenhong peigujia songzhuangu peigu suogu \
date
1990-03-01 1 除权除息 0.0 3.56 0.0 1.0 None
1991-04-03 5 股本变化 NaN NaN NaN NaN None
1991-05-02 1 除权除息 3.0 0.00 4.0 0.0 None
1991-05-02 2 送配股上市 NaN NaN NaN NaN None
1991-08-17 1 除权除息 0.0 0.00 10.0 0.0 None
liquidity_before liquidity_after shares_before shares_after \
date
1990-03-01 NaN NaN NaN NaN
1991-04-03 0.0 2650.000000 0.00000 4850.017090
1991-05-02 NaN NaN NaN NaN
1991-05-02 2650.0 3949.072266 4850.01709 8975.164062
1991-08-17 NaN NaN NaN NaN
fenshu xingquanjia date category_meaning code
date
1990-03-01 None None 1990-03-01 除权除息 000001
1991-04-03 None None 1991-04-03 股本变化 000001
1991-05-02 None None 1991-05-02 除权除息 000001
1991-05-02 None None 1991-05-02 送配股上市 000001
1991-08-17 None None 1991-08-17 除权除息 000001

股票/列表

1
2
3
4
5
6
7
8
9
10
11
12
QA.QA_util_log_info('股票列表')
data = QA.QAFetch.QATdx.QA_fetch_get_stock_list('stock')
data.head()
QUANTAXIS>> 股票列表
Out[13]:
code volunit decimal_point name pre_close sse sec
code sse
000001 sz 000001 100 2 平安银行 568.04250 sz stock_cn
000002 sz 000002 100 2 万 科A 24.01000 sz stock_cn
000004 sz 000004 100 2 国农科技 2008.04750 sz stock_cn
000005 sz 000005 100 2 世纪星源 4226.00875 sz stock_cn
000006 sz 000006 100 2 深振业A 6.14000 sz stock_cn

指数/列表

1
2
3
4
5
6
7
8
9
10
11
12
QA.QA_util_log_info('指数列表')
data = QA.QAFetch.QATdx.QA_fetch_get_stock_list('index')
data.head()
QUANTAXIS>> 指数列表
Out[15]:
code volunit decimal_point name pre_close sse sec
code sse
000001 sh 000001 100 2 上证指数 2729.243896 sh index_cn
000002 sh 000002 100 2 A股指数 2858.179688 sh index_cn
000003 sh 000003 100 2 B股指数 284.528992 sh index_cn
000004 sh 000004 100 2 工业指数 2212.357178 sh index_cn
000005 sh 000005 100 2 商业指数 2346.403564 sh index_cn

指数/日线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
QA.QA_util_log_info('指数日线')
data = QA.QAFetch.QATdx.QA_fetch_get_index_day('000001', '2018-01-01', '2018-09-24')
data.head()
QUANTAXIS>> 指数日线
Out[19]:
open close high low vol amount \
date
2018-01-02 3314.03 3348.33 3349.05 3314.03 2022788.0 2.277885e+11
2018-01-03 3347.74 3369.11 3379.92 3345.29 2138361.0 2.583665e+11
2018-01-04 3371.00 3385.71 3392.83 3365.30 2069552.0 2.430908e+11
2018-01-05 3386.46 3391.75 3402.07 3380.25 2130606.0 2.481878e+11
2018-01-08 3391.55 3409.48 3412.73 3384.56 2361651.0 2.862132e+11
up_count down_count date code date_stamp
date
2018-01-02 1108 230 2018-01-02 000001 1.514822e+09
2018-01-03 947 387 2018-01-03 000001 1.514909e+09
2018-01-04 632 682 2018-01-04 000001 1.514995e+09
2018-01-05 653 663 2018-01-05 000001 1.515082e+09
2018-01-08 700 632 2018-01-08 000001 1.515341e+09

指数/分钟线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
QA.QA_util_log_info('指数分钟线')
QUANTAXIS>> 指数分钟线
data = QA.QAFetch.QATdx.QA_fetch_get_index_min('000001', '2018-01-01', '2018-09-24', '1min')
data.head()
Out[22]:
open close high low vol \
datetime
2018-05-18 09:31:00 3151.08 3152.73 3152.73 3151.08 35048896.0
2018-05-18 09:32:00 3151.84 3150.49 3152.08 3150.25 13337879.0
2018-05-18 09:33:00 3150.00 3150.93 3150.93 3150.00 13658619.0
2018-05-18 09:34:00 3151.08 3153.93 3154.05 3151.08 13372396.0
2018-05-18 09:35:00 3153.72 3155.07 3155.40 3153.72 12654612.0
amount datetime up_count down_count \
datetime
2018-05-18 09:31:00 5.877472e-39 2018-05-18 09:31:00 0 0
2018-05-18 09:32:00 5.877472e-39 2018-05-18 09:32:00 0 0
2018-05-18 09:33:00 5.877472e-39 2018-05-18 09:33:00 0 0
2018-05-18 09:34:00 5.877472e-39 2018-05-18 09:34:00 0 0
2018-05-18 09:35:00 5.877472e-39 2018-05-18 09:35:00 0 0
code date date_stamp time_stamp type
datetime
2018-05-18 09:31:00 000001 2018-05-18 1.526573e+09 1.526607e+09 1min
2018-05-18 09:32:00 000001 2018-05-18 1.526573e+09 1.526607e+09 1min
2018-05-18 09:33:00 000001 2018-05-18 1.526573e+09 1.526607e+09 1min
2018-05-18 09:34:00 000001 2018-05-18 1.526573e+09 1.526607e+09 1min
2018-05-18 09:35:00 000001 2018-05-18 1.526573e+09 1.526607e+09 1min

期货/日线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
QA.QA_util_log_info('期货日线')
data = QA.QAFetch.QATdx.QA_fetch_get_future_day('RBL8', '2018-01-01', '2018-09-24')
data.head()
QUANTAXIS>> 期货日线
Out[27]:
open high low close position trade price \
date
2018-01-02 3801.0 3886.0 3794.0 3874.0 2413572 29614 3842.0
2018-01-03 3866.0 3877.0 3803.0 3809.0 2433636 35238 3845.0
2018-01-04 3805.0 3842.0 3788.0 3819.0 2581090 37477 3811.0
2018-01-05 3812.0 3827.0 3760.0 3798.0 2744436 39411 3791.0
2018-01-08 3795.0 3820.0 3733.0 3818.0 2717212 43292 3772.0
amount date code date_stamp
date
2018-01-02 3.382135e-39 2018-01-02 RBL8 1.514822e+09
2018-01-03 3.410250e-39 2018-01-03 RBL8 1.514909e+09
2018-01-04 3.616877e-39 2018-01-04 RBL8 1.514995e+09
2018-01-05 3.845774e-39 2018-01-05 RBL8 1.515082e+09
2018-01-08 3.807625e-39 2018-01-08 RBL8 1.515341e+09

最新交易价格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
QA.QA_util_log_info('最后一次交易价格')
QUANTAXIS>> 最后一次交易价格
QA.QA_util_log_info('参数为列表')
QUANTAXIS>> 参数为列表
data = QA.QAFetch.QATdx.QA_fetch_get_stock_latest(['000001', '000002'])
data.head()
Out[34]:
open close high low vol amount code \
date
2018-09-21 10.26 10.67 10.7 10.18 1624518.0 1.707850e+09 000001
2018-09-21 24.20 25.80 26.0 23.93 1064216.0 2.663501e+09 000002
date date_stamp
date
2018-09-21 2018-09-21 1.537459e+09
2018-09-21 2018-09-21 1.537459e+09

QA.QA_util_log_info('参数为一只股票')
QUANTAXIS>> 参数为一只股票
data = QA.QAFetch.QATdx.QA_fetch_get_stock_latest('000001')
data.head()
Out[37]:
open close high low vol amount code \
date
2018-09-21 10.26 10.67 10.7 10.18 1624518.0 1.707850e+09 000001
date date_stamp
date
2018-09-21 2018-09-21 1.537459e+09

实时上下五档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
QA.QA_util_log_info('实时价格')
QUANTAXIS>> 实时价格
data = QA.QAFetch.QATdx.QA_fetch_get_stock_realtime(['000001', '000002'])
data.head()
Out[43]:
datetime active1 active2 last_close code \
code
000001 2018-09-24 12:10:03.516664 4525 4525 10.23 000001
000002 2018-09-24 12:10:03.516664 4639 4639 24.01 000002
open high low price cur_vol ... bid3 bid_vol3 ask4 \
code ...
000001 10.26 10.7 10.18 10.67 27906 ... 10.64 1523 10.70
000002 24.20 26.0 23.93 25.80 15259 ... 25.77 556 25.83
ask_vol4 bid4 bid_vol4 ask5 ask_vol5 bid5 bid_vol5
code
000001 16192 10.63 3604 10.71 3682 10.62 2010
000002 1394 25.76 203 25.84 146 25.75 506
[2 rows x 33 columns]

分笔数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
QA.QA_util_log_info('分笔数据')
QUANTAXIS>> 分笔数据
## 历史分笔
data = QA.QAFetch.QATdx.QA_fetch_get_stock_transaction('000001', '2018-09-11', '2018-09-24')
data.head()
Out[6]:
time price vol buyorsell date \
datetime
2018-09-11 09:30:00 09:30 9.90 2448 2 2018-09-11
2018-09-11 09:30:00 09:30 9.90 234 1 2018-09-11
2018-09-11 09:30:00 09:30 9.91 1388 0 2018-09-11
2018-09-11 09:30:00 09:30 9.90 2312 1 2018-09-11
2018-09-11 09:30:00 09:30 9.90 170 1 2018-09-11
datetime code order
datetime
2018-09-11 09:30:00 2018-09-11 09:30:00 000001 0
2018-09-11 09:30:00 2018-09-11 09:30:00 000001 1
2018-09-11 09:30:00 2018-09-11 09:30:00 000001 2
2018-09-11 09:30:00 2018-09-11 09:30:00 000001 3
2018-09-11 09:30:00 2018-09-11 09:30:00 000001 4

## 实时分笔
data = QA.QAFetch.QATdx.QA_fetch_get_stock_transaction_realtime('000001')
data.head()
Out[9]:
time price vol num buyorsell date \
datetime
2018-09-24 09:25:00 09:25 10.26 3193 66 2 2018-09-24
2018-09-24 09:30:00 09:30 10.28 434 6 0 2018-09-24
2018-09-24 09:30:00 09:30 10.28 8848 109 1 2018-09-24
2018-09-24 09:30:00 09:30 10.28 1775 47 0 2018-09-24
2018-09-24 09:30:00 09:30 10.29 68 5 0 2018-09-24
datetime code order
datetime
2018-09-24 09:25:00 2018-09-24 09:25:00 000001 0
2018-09-24 09:30:00 2018-09-24 09:30:00 000001 1
2018-09-24 09:30:00 2018-09-24 09:30:00 000001 2
2018-09-24 09:30:00 2018-09-24 09:30:00 000001 3
2018-09-24 09:30:00 2018-09-24 09:30:00 000001 4

板块数据

1
2
3
4
5
6
7
8
9
10
11
QUANTAXIS>> 板块数据
data = QA.QAFetch.QATdx.QA_fetch_get_stock_block()
data.head()
Out[12]:
blockname code type source
code
000001 通达信88 000001 gn tdx
000002 通达信88 000002 gn tdx
000008 通达信88 000008 gn tdx
000028 通达信88 000028 gn tdx
000157 通达信88 000157 gn tdx

从数据库里获取数据

股票/日线

1
2
3
4
5
6
7
8
9
10
da = QA.QA_fetch_stock_day_adv('000001', '2018-01-01', '2018-09-24')
da.data.head()
Out[15]:
open high low close volume amount
date code
2018-01-02 000001 13.35 13.93 13.32 13.70 2081592.0 2.856544e+09
2018-01-03 000001 13.73 13.86 13.20 13.33 2962498.0 4.006221e+09
2018-01-04 000001 13.32 13.37 13.13 13.25 1854509.0 2.454544e+09
2018-01-05 000001 13.21 13.35 13.15 13.30 1210312.0 1.603289e+09
2018-01-08 000001 13.25 13.29 12.86 12.96 2158620.0 2.806099e+09

股票/分钟线

可以选择1min/5min/15min/30min/60min。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
da = QA.QA_fetch_stock_min_adv('000001', '2018-01-01', '2018-09-24', '1min')
da.data.head()
Out[19]:
open high low close volume amount \
datetime code
2018-04-11 09:31:00 000001 11.39 11.52 11.39 11.51 4909400.0 56181776.0
2018-04-11 09:32:00 000001 11.52 11.52 11.43 11.44 1823600.0 20935914.0
2018-04-11 09:33:00 000001 11.44 11.50 11.43 11.50 2343400.0 26846598.0
2018-04-11 09:34:00 000001 11.50 11.55 11.50 11.55 3101900.0 35774592.0
2018-04-11 09:35:00 000001 11.56 11.60 11.55 11.60 4845100.0 56038280.0
high_limit low_limit
datetime code
2018-04-11 09:31:00 000001 NaN NaN
2018-04-11 09:32:00 000001 12.66 10.36
2018-04-11 09:33:00 000001 12.58 10.30
2018-04-11 09:34:00 000001 12.65 10.35
2018-04-11 09:35:00 000001 12.71 10.40

指数/基金日线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
da = QA.QA_fetch_index_day_adv('000001', '2018-01-01', '2018-09-24')
da.data.head()
Out[23]:
open high low close up_count down_count \
date code
2018-01-02 000001 3314.03 3349.05 3314.03 3348.33 1108 230
2018-01-03 000001 3347.74 3379.92 3345.29 3369.11 947 387
2018-01-04 000001 3371.00 3392.83 3365.30 3385.71 632 682
2018-01-05 000001 3386.46 3402.07 3380.25 3391.75 653 663
2018-01-08 000001 3391.55 3412.73 3384.56 3409.48 700 632
volume amount
date code
2018-01-02 000001 2022788.0 2.277885e+11
2018-01-03 000001 2138361.0 2.583665e+11
2018-01-04 000001 2069552.0 2.430908e+11
2018-01-05 000001 2130606.0 2.481878e+11
2018-01-08 000001 2361651.0 2.862132e+11

指数/基金日线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
da = QA.QA_fetch_index_min_adv('000001', '2018-01-01', '2018-09-24', '1min')
da.data.head()
Out[25]:
open high low close up_count \
datetime code
2018-04-11 09:31:00 000001 3197.37 3202.06 3197.37 3202.06 0
2018-04-11 09:32:00 000001 3201.70 3201.70 3198.35 3198.35 0
2018-04-11 09:33:00 000001 3198.08 3198.22 3197.23 3197.68 0
2018-04-11 09:34:00 000001 3197.61 3200.66 3197.61 3200.66 0
2018-04-11 09:35:00 000001 3200.99 3203.54 3200.99 3203.54 0
down_count volume amount
datetime code
2018-04-11 09:31:00 000001 0 60319568.0 5.877472e-39
2018-04-11 09:32:00 000001 0 30036900.0 5.877472e-39
2018-04-11 09:33:00 000001 0 25952792.0 5.877472e-39
2018-04-11 09:34:00 000001 0 24751630.0 5.877472e-39
2018-04-11 09:35:00 000001 0 23551330.0 5.877472e-39

板块

1
2
3
4
5
6
7
8
9
10
da = QA.QA_fetch_stock_block_adv()
da.data.head()
Out[29]:
source type
blockname code
通达信88 000001 tdx gn
000002 tdx gn
000008 tdx gn
000028 tdx gn
000157 tdx gn
# Python

评论

程振兴

程振兴 @czxa.top
截止今天,我已经在本博客上写了604.4k个字了!

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×