tushate 简单入门教程
tushare 是一个需要通过接口获取数据的平台,可以较为简单获取比较全面的股票、期货、基金等数据信息,本文通过python SDK来获取数据
步骤
1.下载python3.0以上版本
2.在cmd界面输入:pip install tushare
3.注册tushare账号(https://waditu.com),获取属于你自己的token
4.打开shell(或者任何python代码编写界面)界面
import tushare as ts
ts.set_token('这里是你的token')
pro = ts.pro_api()
df = pro.trade_cal(exchange='', start_date='20180901', end_date='20181001',fields='exchange,cal_date,is_open,pretrade_date', is_open='0')
print(df)
结果:
代码解释:
①trade_cal 是接口名;
②exchange=’’,start_date=‘20180901’, end_date='20181001’是当前接口下的输入参数(可理解为查询条件),可以根据tushare数据接口给出的详细解释进行编写;③fields='exchange,cal_date,is_open,pretrade_date’属于这个接口的输出参数,也是输出的表头
如果想要输出所有的沪深股票信息
打开tushare的数据接口 > 点击沪深股票 > 点击股票基础列表 > 得到下图
data = pro.stock_basic(exchange='',list_status='L',fields='ts_code,symbol,name,area,industry,list_date')
exchange=’’ 表示默认上交所和深交所的股票信息都输出;
list_status='L’表示上市状态为“上市”;
fields=‘ts_code,symbol,name,area,industry,list_date’ 这些是输出参数也是表头,根据上图所示都有其特定含义。
结果共4303条数据: