壹、安裝TuShare
方式1:pip install tushare
方式2:訪問https://pypi.python.org/pypi/tushare/下載安裝
方式3:將源代碼下載到本地python setup.py install
二、升級TuShare
1、先查看本地與線上的版本版本號:
pip search tushare
2、升級TuShare:
pip install tushare --upgrade
確認安裝成功
import tushare as ts
print ts.__version__
import tushare as ts
df = ts.get_hist_data(‘600848’)
ts.get_hist_data(‘600848’,ktype='W‘) #獲取周k線數據
ts.get_hist_data('600848’,ktype='M‘) #獲取月k線數據
ts.get_hist_data('600848’,ktype='5‘) #獲取5分鐘k線數據
ts.get_hist_data('600848’,ktype='15‘) #獲取15分鐘k線數據
ts.get_hist_data('600848’,ktype='30‘) #獲取30分鐘k線數據
ts.get_hist_data('600848’,ktype='60‘) #獲取60分鐘k線數據
ts.get_hist_data('sh’)#獲取上證指數k線數據,其它參數與個股壹致,下同
ts.get_hist_data(‘sz’)#獲取深圳成指k線數據 ts.get_hist_data(‘hs300’)#獲取滬深300指數k線數據
ts.get_hist_data(‘sz50’)#獲取上證50指數k線數據
ts.get_hist_data(‘zxb’)#獲取中小板指數k線數據
ts.get_hist_data(‘cyb’)#獲取創業板指數k線數據
Python財經數據接口包TuShare的使用
獲取歷史分筆數據
df = ts.get_tick_data(‘000756','2015-03-27’)
df.head(10)
Python財經數據接口包TuShare的使用
獲取實時分筆數據
df = ts.get_realtime_quotes(‘000581’)
print df[['code','name','price','bid','ask','volume','amount','time']]
返回值說明:
0:name,股票名字
1:open,今日開盤價
2:pre_close,昨日收盤價
3:price,當前價格
4:high,今日最高價
5:low,今日最低價
6:bid,競買價,即“買壹”報價
7:ask,競賣價,即“賣壹”報價
8:volumn,成交量 maybe you need do volumn/100
9:amount,成交金額(元 CNY)
10:b1_v,委買壹(筆數 bid volume)
11:b1_p,委買壹(價格 bid price)
12:b2_v,“買二”
13:b2_p,“買二”
14:b3_v,“買三”
15:b3_p,“買三”
16:b4_v,“買四”
17:b4_p,“買四”
18:b5_v,“買五”
19:b5_p,“買五”
20:a1_v,委賣壹(筆數 ask volume)
21:a1_p,委賣壹(價格 ask price)
…
30:date,日期
31:time,時間