tushare

TuShare is a utility for crawling historical data of China stocks

BSD-3-CLAUSE License

Stars
12.8K

TuShare

Tushare Pro https://tushare.pro

TuShare/******** ****,

TuSharetushare

QQ

  • 14934432
  • 658562506
  • 665480579
  • () 527416821

Dependencies

python 2.x/3.x

pandas

Installation

Upgrade

pip install tushare --upgrade

Quick Start

Example 1.

import tushare as ts

ts.get_hist_data('600848') #
get_k_data
   5102051020
			 open    high   close     low     volume    p_change  ma5 \
date                                                                     
2012-01-11   6.880   7.380   7.060   6.880   14129.96     2.62   7.060   
2012-01-12   7.050   7.100   6.980   6.900    7895.19    -1.13   7.020   
2012-01-13   6.950   7.000   6.700   6.690    6611.87    -4.01   6.913   
2012-01-16   6.680   6.750   6.510   6.480    2941.63    -2.84   6.813   
2012-01-17   6.660   6.880   6.860   6.460    8642.57     5.38   6.822   
2012-01-18   7.000   7.300   6.890   6.880   13075.40     0.44   6.788   
2012-01-19   6.690   6.950   6.890   6.680    6117.32     0.00   6.770   
2012-01-20   6.870   7.080   7.010   6.870    6813.09     1.74   6.832 

			 ma10    ma20      v_ma5     v_ma10     v_ma20     turnover  
date                                                                  
2012-01-11   7.060   7.060   14129.96   14129.96   14129.96     0.48  
2012-01-12   7.020   7.020   11012.58   11012.58   11012.58     0.27  
2012-01-13   6.913   6.913    9545.67    9545.67    9545.67     0.23  
2012-01-16   6.813   6.813    7894.66    7894.66    7894.66     0.10  
2012-01-17   6.822   6.822    8044.24    8044.24    8044.24     0.30  
2012-01-18   6.833   6.833    7833.33    8882.77    8882.77     0.45  
2012-01-19   6.841   6.841    7477.76    8487.71    8487.71     0.21  
2012-01-20   6.863   6.863    7518.00    8278.38    8278.38     0.23  

  

ts.get_hist_data('600848',start='2015-01-05',end='2015-01-09')

			open    high   close     low    volume   p_change     ma5    ma10 \  
date                                                                            
2015-01-05  11.160  11.390  11.260  10.890  46383.57     1.26  11.156  11.212   
2015-01-06  11.130  11.660  11.610  11.030  59199.93     3.11  11.182  11.155   
2015-01-07  11.580  11.990  11.920  11.480  86681.38     2.67  11.366  11.251   
2015-01-08  11.700  11.920  11.670  11.640  56845.71    -2.10  11.516  11.349   
2015-01-09  11.680  11.710  11.230  11.190  44851.56    -3.77  11.538  11.363   
 			ma20     v_ma5    v_ma10     v_ma20 	 turnover  
date                                                        
2015-01-05  11.198  58648.75  68429.87   97141.81     1.59  
2015-01-06  11.382  54854.38  63401.05   98686.98     2.03  
2015-01-07  11.543  55049.74  61628.07  103010.58     2.97  
2015-01-08  11.647  57268.99  61376.00  105823.50     1.95  
2015-01-09  11.682  58792.43  60665.93  107924.27     1.54  

ts.get_h_data('002337') #
ts.get_h_data('002337',autype='hfq') #
ts.get_h_data('002337',autype=None) #
ts.get_h_data('002337',start='2015-01-01',end='2015-03-16') #

Example 2.

ts.get_today_all()
	  code    name     changepercent  trade   open   high    low  settlement \  
0     002738           10.023  19.32  19.32  19.32  19.32       17.56   
1     300410           10.022  25.03  25.03  25.03  25.03       22.75   
2     002736           10.013  16.37  16.37  16.37  16.37       14.88   
3     300412           10.010  31.54  31.54  31.54  31.54       28.67   
4     300411           10.007  29.68  29.68  29.68  29.68       26.98   
5     603636           10.006  38.15  38.15  38.15  38.15       34.68   
6     002664           10.004  30.68  29.00  30.68  28.30       27.89   
7     300367           10.004  86.76  78.00  86.76  77.87       78.87   
8     601299           10.000  11.44  11.44  11.44  11.29       10.40   
9     601880            10.000   5.72   5.34   5.72   5.22        5.20   
10    000856           10.000   8.91   8.18   8.91   8.18        8.10  
		volume  	 turnoverratio  
0        375100        1.25033  
1         85800        0.57200  
2       1058925        0.08824  
3         69400        0.51791  
4        252220        1.26110  
5       1374630        5.49852  
6       6448748        9.32700  
7       2025030        6.88669  
8     433453523        4.28056  
9     323469835        9.61735  
10     25768152       19.51090  

Example 3.

import tushare as ts

df = ts.get_tick_data('600848',date='2014-01-09')
df.head(10)

()

Out[3]: 
 	 time  		price change  volume  amount  type
0    15:00:00   6.05     --       8    4840   
1    14:59:55   6.05     --      50   30250   
2    14:59:35   6.05     --      20   12100   
3    14:59:30   6.05  -0.01     165   99825   
4    14:59:20   6.06   0.01       4    2424   
5    14:59:05   6.05  -0.01       2    1210   
6    14:58:55   6.06     --       4    2424   
7    14:58:45   6.06     --       2    1212   
8    14:58:35   6.06   0.01       2    1212   
9    14:58:25   6.05  -0.01      20   12100   
10   14:58:05   6.06     --       5    3030   

Example 4. (Realtime Quotes Data)

df = ts.get_realtime_quotes('000581') #Single stock symbol
df[['code','name','price','bid','ask','volume','amount','time']]

...more in docs

   code    name     price  bid    ask    volume   amount        time
0  000581    31.15  31.14  31.15  8183020  253494991.16  11:30:36 

30

ts.get_realtime_quotes(['600848','000980','000981']) #symbols from a list
ts.get_realtime_quotes(df['code'].tail(10)) #from a Series

========

https://tushare.pro

http://tushare.org/

Change Logs

1.2.17 2018/11/24

  • Pro
  • ProA/
  • Propro_bar///

1.2.15 2018/10/15

  • pro_bar
  • set_token

1.2.12 2018/08/10

1.0.5 2017/11/12

  • bug

1.0.2 2017/10/29

  • barETF
  • tick
  • bug

0.9.2 2017/09/13

  • ,okcoin
  • bug

0.8.8 2017/08/29

  • get_day_all
  • BDI

0.8.0 2017/06/05

  • 6debugo
  • bug

0.7.6 2017/05/16

  • get_today_all
  • forecast_data mac

0.7.0 2017/03/12

  • get_today_all

0.6.2 2016/12/03

  • top10_holders
  • global_realtime
  • bug

0.6.1 2016/11/22

  • get_k_databug

0.5.6 2016/11/06

  • get_k_data(tushare)
  • bug

0.5.1 2016/10/16

  • bug

0.4.9 2016/03/26

  • get_industry_classified(standard='sw')
  • trade_cal()
  • bug

0.4.3 2015/12/24

  • bug

0.4.1 2015/11/27

  • sina
  • bug

0.3.9 2015/10/13

0.3.8 2015/09/19

  • 300
  • bug

0.3.5 2015/07/27

0.3.4 2015/06/15

  • get_h_datafloat

  • get_indexopen

  • GitHubbug

0.2.8 2015/04/28

  • get_h_databug

0.2.6

  • null300

0.2.5 2015/04/16

  • python2.xpython3.x
  • 500
  • bug

0.2.3 2015/04/11

  • columnbug

0.2.0 2015/03/17

  • 300
  • 50
  • float

0.1.9 2015/02/06

0.1.6 2015/01/27

  • docs

0.1.5 2015/01/26

0.1.3 2015/01/13

  • Done for crawling Realtime Quotes data

0.1.1 2015/01/11

  • tick

0.1.0 2014/12/01

Related Projects