Current location - Music Encyclopedia - Chinese History - How to use tushare's interface
How to use tushare's interface
Install TuShare

Mode 1: pip installation tushare

Mode 2: Visit https://pypi.python.org/pypi/tushare/ to download and install.

Method 3: download the source code to local python setup.py install.

Upgrade TuShare

1. First check the local and online version numbers:

Pip search tushare

2. Upgrade TuShare:

Pip installation tushare-upgrade

Confirm that the installation is successful.

Import tushare as ts.

Print ts. _ _ Version _ _

Obtain historical transaction data

Import tushare as ts.

df = ts.get_hist_data('600848 ')

Ts.get _ hist _ data ('600848', ktype =' w') # Get weekly K-line data.

Ts.get_hist_data('600848', ktype =' m') # Get monthly K-line data.

Ts.get_hist_data('600848', ktype =' 5') # Get 5 minutes of K-line data.

Ts.get_hist_data('600848', ktype =' 15') # Get 15 minute K-line data.

Ts.get_hist_data('600848', ktype =' 30') # Get 30 minutes of K-line data.

Ts.get_hist_data('600848', ktype =' 60') # Get 60 minutes of K-line data.

Ts.get_hist_data('sh')# Obtain the K-line data of the Shanghai Composite Index, and other parameters are consistent with individual stocks, the same below.

Ts.get _ hist _ data ('SZ') # Get K-line data of Shenzhen Stock Exchange Index TS.get _ hist _ data ('hs300') # Get K-line data of Shanghai and Shenzhen 300 Index.

Ts。 Get _ hist _ data ('sz50') # Get the K-line data of SSE 50 Index.

Ts。 Get _ hist _ data ('zxb') # Get K-line data of small and medium-sized board index.

Ts.get _ hist _ data ('cyb') # Get the K-line data of GEM index.

Use of Python financial data interface package TuShare

Get historical minute data

df = ts.get_tick_data('000756 ',' 20 15-03-27 ')

df.head( 10)

Use of Python financial data interface package TuShare

Get real-time minute data

df = ts . get _ real time _ quotes(' 00058 1 ')

Print df[[' code',' name',' price',' bid',' asking price',' quantity',' amount',' time']]

Description of the return value:

0: Name, stock name

1: Opening price, opening price today.

2: pre _ close, yesterday's closing price

3. Price, current price

4: High, the highest price today.

5: Low, the lowest price today.

6. Bid, bid, that is, "buy one get one free" offer.

7: Q, the auction price, that is, the quotation of "selling one".

8: volumn, volume You may need to do volumn/ 100.

9: amount, transaction amount (CNY)

10: b 1 _ v, a bid amount.

1 1: b 1 _ p, entrust to buy one (bid).

12: B2 _ V, "buy two"

13: B2 _ p, "buy two"

14: B3 _ V, "buy three"

15: B3 _ p, "buy three"

16: B4 _ V," Maisi "

17: B4 _ p, "buy four"

18: b5 _ v, "buy five"

19: b5 _ p, "buy five"

20: a 1 _ v, one batch (number of pens)

2 1: A 1 _ P, one commission (asking price)

30: date, date

3 1: time, time