天天看點

Tushare金融資料API使用介紹(股票API、币API)Tushare簡介

Tushare 金融資料API

  • Tushare簡介
    • 安裝方法
    • 資料介紹
    • 使用執行個體(擷取一支股票在一段時間内的日資料,并畫出K線圖)

Tushare簡介

Tushare是一個免費、開源的python财經資料接口包。擁有豐富的資料内容,如股票、基金、期貨、數字貨币等行情資料,公司财務、基金經理等基本面資料,後續開通債券、外彙、行業、大資料、區塊鍊。Tushare傳回的絕大部分的資料格式都是pandas DataFrame類型,非常便于用pandas/NumPy/Matplotlib進行資料分析和可視化。官方網站為:https://tushare.pro/

安裝方法

pip install tushare

資料介紹

滬深股票的資料包括日線行情、複權因子、停複牌資訊、每日名額、利潤表、資産負債表、現金流量表、業績預告、分紅送股、業績快報、财務名額資料、财務審計意見、主營業務構成、滬深港通資金流向、滬深股通十大成交股、港股通十大成交股、融資融券交易彙總、融資融券交易明細、前十大股東、龍虎榜每日明細等資料;

Tushare還為廣大的币圈朋友提供了豐富多樣的區塊鍊相關資料,比如數字貨币每日市值、數字貨币行情、交易所交易費率、比特币每日市值、比特币每日量價、優币指數成分。相關資料接口定義請參考https://tushare.pro/document/2

使用執行個體(擷取一支股票在一段時間内的日資料,并畫出K線圖)

代碼中的ts.set_token值需要注冊擷取,注冊位址為 https://tushare.pro/register?reg=123961

from pyecharts import Kline
import tushare as ts
import pandas as pd
ts.set_token('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
pro = ts.pro_api()
df1 = pro.daily(ts_code='000938.SZ', start_date='20150401', end_date='20180930')
df=df1.sort_values(by=['trade_date'])
df.reset_index(level=0,inplace=True)
df.drop(['index'],axis=1,inplace=True)
print(df)
df.to_csv("aaa.csv")
date=df.trade_date.tolist()
data=[]
for idx in df.index :
     row=[df.iloc[idx]['open'],df.iloc[idx]['close'],df.iloc[idx]['low'],df.iloc[idx]['high']]
     data.append(row)
kline = Kline("K 線圖示例")
kline.add(
    "日K",
    date,
    data,
    mark_point=["max"],
    is_datazoom_show=True,
)
kline.render()
                
Tushare金融資料API使用介紹(股票API、币API)Tushare簡介

繼續閱讀