如何获取分钟数据?


Tushare Pro提供了包括股票、指数、基金、期货、港股在内的各类资产交易行情的分钟数据。但由于数据量庞大,服务器和带宽成本压力很大,目前股票、期货、期权分钟是分别单独开权限的,跟平台积分没有关系,可以参考权限列表说明

在使用方面,具体参数说明,可以参考通用行情接口获取更加详细的信息。

需要注意的几点:

  • 分钟数据需要单独开权限才可以正常使用,否则只有试用权限,开权限请在QQ群里联系群主或加微信migedata
  • 由于服务器资源有限,目前只能一个个标的按时间段获取分钟,单次提取最多8000行数据
  • 数据只供策略研究和学习使用,不允许作为商业目的
  • 目前分钟频度包括1分、5、15、30、60分数据
  • 数据每天收盘后处理更新,时间在17~21点之间完成
  • 分钟数据时间参数请使用带时分秒的格式,比如:2019-06-04 19:00:00
  • 如是end_date输入的是不带时分秒的日期,返回的数据不包括end_date当日,即数据返回的是 < end_date的数据

如果你已经拥有了分钟数据权限,可以通过以下推荐的方式来获取数据:

import tushare as ts

#获取股票1分钟数据
df = ts.pro_bar(ts_code='600000.SH',
                    freq='1min', 
                    start_date='2020-01-07 09:00:00', 
                    end_date='2020-01-08 17:00:00')

print(df)

       ts_code           trade_time   open  close   high    low     vol  \
0    600000.SH  2020-01-08 09:31:00  12.41  12.44  12.45  12.41  880140   
1    600000.SH  2020-01-08 10:14:00  12.37  12.37  12.38  12.37   61300   
2    600000.SH  2020-01-08 10:19:00  12.36  12.36  12.37  12.36  288400   
3    600000.SH  2020-01-08 10:29:00  12.34  12.33  12.35  12.33  119100   
4    600000.SH  2020-01-08 10:33:00  12.33  12.33  12.34  12.33  218700   
5    600000.SH  2020-01-08 10:59:00  12.38  12.37  12.38  12.36   76600   
6    600000.SH  2020-01-08 11:09:00  12.37  12.36  12.37  12.36   44777   
7    600000.SH  2020-01-08 11:15:00  12.37  12.37  12.38  12.37   67500   
8    600000.SH  2020-01-08 13:08:00  12.36  12.37  12.37  12.36   72300   
9    600000.SH  2020-01-08 13:10:00  12.36  12.37  12.37  12.36   43300   
10   600000.SH  2020-01-08 13:15:00  12.35  12.36  12.36  12.35   46900   
11   600000.SH  2020-01-08 13:27:00  12.33  12.34  12.34  12.33   29300   
12   600000.SH  2020-01-08 13:31:00  12.33  12.35  12.35  12.33  102301   
13   600000.SH  2020-01-08 14:05:00  12.30  12.29  12.30  12.29   88000   
14   600000.SH  2020-01-08 14:09:00  12.30  12.30  12.30  12.29   26400   
15   600000.SH  2020-01-08 14:15:00  12.28  12.28  12.29  12.28   80926   
16   600000.SH  2020-01-08 14:45:00  12.30  12.31  12.32  12.29  226800  

#获取指数分钟数据
df = ts.pro_bar(ts_code='000001.SH',
                    asset='I',
                    freq='1min', 
                    start_date='2020-01-07 09:00:00', 
                    end_date='2020-01-08 17:00:00')    

print(df)

       ts_code           trade_time      open     close      high       low  \
0    000001.SH  2020-01-08 09:30:00  3094.239  3094.239  3094.239  3094.239   
1    000001.SH  2020-01-08 09:34:00  3089.337  3091.416  3091.416  3089.311   
2    000001.SH  2020-01-08 09:36:00  3092.239  3089.240  3092.239  3089.240   
3    000001.SH  2020-01-08 09:37:00  3089.347  3089.743  3089.940  3089.347   
4    000001.SH  2020-01-08 09:38:00  3089.405  3085.691  3089.862  3085.374   
5    000001.SH  2020-01-08 09:40:00  3084.808  3088.857  3088.857  3084.808   
6    000001.SH  2020-01-08 09:48:00  3090.286  3088.414  3090.350  3088.414   
7    000001.SH  2020-01-08 09:52:00  3086.431  3085.874  3086.502  3085.469   
8    000001.SH  2020-01-08 09:56:00  3087.642  3087.394  3088.178  3087.394   
9    000001.SH  2020-01-08 09:59:00  3087.177  3086.959  3087.568  3086.754   
10   000001.SH  2020-01-08 10:06:00  3090.386  3090.284  3090.741  3089.893   
11   000001.SH  2020-01-08 10:14:00  3085.475  3084.236  3085.475  3084.236   
12   000001.SH  2020-01-08 10:18:00  3081.099  3081.567  3081.581  3080.709   
13   000001.SH  2020-01-08 10:39:00  3082.920  3083.558  3083.558  3082.769   
14   000001.SH  2020-01-08 10:46:00  3084.164  3084.402  3084.802  3083.929   
15   000001.SH  2020-01-08 10:50:00  3084.594  3084.198  3084.594  3083.419  


#获取基金1分钟数据
df = ts.pro_bar(ts_code='150018.SZ',
                    asset='FD',
                    freq='1min', 
                    start_date='2020-01-07 09:00:00', 
                    end_date='2020-01-08 17:00:00')    



#获取期货1分钟数据
df = ts.pro_bar(ts_code='CU2012.SHF',
                    asset='FT',
                    freq='1min', 
                    start_date='2020-01-07 09:00:00', 
                    end_date='2020-01-08 17:00:00')    
                    
print(df)

        ts_code           trade_time     open    close     high      low  vol  \
0    CU2012.SHF  2020-01-08 00:00:00  49300.0  49300.0  49300.0  49300.0    2   
1    CU2012.SHF  2020-01-08 00:08:00  49300.0  49300.0  49300.0  49300.0    0   
2    CU2012.SHF  2020-01-08 00:14:00  49300.0  49300.0  49300.0  49300.0    0   
3    CU2012.SHF  2020-01-08 00:18:00  49300.0  49300.0  49300.0  49300.0    0   
4    CU2012.SHF  2020-01-08 00:29:00  49300.0  49300.0  49300.0  49300.0    0   
5    CU2012.SHF  2020-01-08 00:36:00  49300.0  49300.0  49300.0  49300.0    0   
6    CU2012.SHF  2020-01-08 00:40:00  49300.0  49300.0  49300.0  49300.0    0   
7    CU2012.SHF  2020-01-08 00:45:00  49300.0  49300.0  49300.0  49300.0    0   
8    CU2012.SHF  2020-01-08 00:51:00  49300.0  49300.0  49300.0  49300.0    0   
9    CU2012.SHF  2020-01-08 01:00:00  49300.0  49300.0  49300.0  49300.0    0   
10   CU2012.SHF  2020-01-08 09:11:00  49300.0  49300.0  49300.0  49300.0    0   
11   CU2012.SHF  2020-01-08 09:20:00  49300.0  49300.0  49300.0  49300.0    0   
12   CU2012.SHF  2020-01-08 09:22:00  49300.0  49300.0  49300.0  49300.0    0   
13   CU2012.SHF  2020-01-08 09:23:00  49300.0  49310.0  49310.0  49300.0    8   
14   CU2012.SHF  2020-01-08 09:36:00  49310.0  49310.0  49310.0  49310.0    0   
15   CU2012.SHF  2020-01-08 09:38:00  49310.0  49310.0  49310.0  49310.0    0   


#获取数字货币分钟数据
df = pro.coin_mins(symbol='btcusdt',
                    exchange='huobi',
                    freq='1min', 
                    trade_date='20200107')

print(df)

       symbol                 date     open     high      low    close  \
0     btcusdt  2020-01-07 00:00:00  7519.82  7529.11  7514.65  7528.39   
1     btcusdt  2020-01-07 00:01:00  7527.31  7530.78  7526.02  7527.81   
2     btcusdt  2020-01-07 00:02:00  7527.40  7528.94  7525.00  7525.58   
3     btcusdt  2020-01-07 00:03:00  7525.11  7529.00  7524.12  7526.00   
4     btcusdt  2020-01-07 00:04:00  7526.01  7526.49  7520.63  7521.90   
5     btcusdt  2020-01-07 00:05:00  7522.47  7522.60  7517.34  7517.39   
6     btcusdt  2020-01-07 00:06:00  7517.39  7519.13  7515.17  7516.09   
7     btcusdt  2020-01-07 00:07:00  7516.90  7516.90  7511.00  7512.83   
8     btcusdt  2020-01-07 00:08:00  7511.46  7513.72  7510.00  7512.71   
9     btcusdt  2020-01-07 00:09:00  7512.73  7515.43  7510.61  7511.86   
10    btcusdt  2020-01-07 00:10:00  7512.09  7521.82  7511.41  7521.82   
11    btcusdt  2020-01-07 00:11:00  7521.81  7532.72  7521.65  7532.08   
12    btcusdt  2020-01-07 00:12:00  7532.08  7532.08  7527.00  7529.15   
13    btcusdt  2020-01-07 00:13:00  7529.79  7539.86  7529.79  7537.73   
14    btcusdt  2020-01-07 00:14:00  7537.72  7538.91  7535.38  7535.38   
15    btcusdt  2020-01-07 00:15:00  7535.00  7545.66  7534.40  7544.30   
16    btcusdt  2020-01-07 00:16:00  7544.23  7546.75  7540.00  7540.74 
置顶