下面介绍两种常用的数据调取方式:
1、已经在山西证券开户并开通PTrade业务
2、已经获取到山西证券Tushare的token码
导入山西证券专用的tushare库(下载地址咨询山西证券的客服热线:95573)
import sxsc_tushare as sx
设置token
sx.set_token("**********************************")
以上方法只需要在第一次或者token失效后调用,完成调取tushare数据凭证的设置,正常情况下不需要重复设置。
初始化pro接口
pro = sx.get_api(env="***")
生产环境:pro=sx.get_api(env="qa")
仿真环境:pro=sx.get_api(env="prd")
纯Python环境:pro=sx.get_api(env="prd")
数据调取
以获取交易日历信息为例:
df = pro.trade_cal(exchange='', start_date='20180901', end_date='20181001', fields='exchange,cal_date,is_open,pretrade_date', is_open='0')
或者
df = pro.query('trade_cal', exchange='', start_date='20180901', end_date='20181001', fields='exchange,cal_date,is_open,pretrade_date', is_open='0')
调取结果:
exchange cal_date is_open pretrade_date
0 SSE 20180901 0 20180831
1 SSE 20180902 0 20180831
2 SSE 20180908 0 20180907
3 SSE 20180909 0 20180907
4 SSE 20180915 0 20180914
5 SSE 20180916 0 20180914
6 SSE 20180922 0 20180921
7 SSE 20180923 0 20180921
8 SSE 20180924 0 20180921
9 SSE 20180929 0 20180928
10 SSE 20180930 0 20180928
11 SSE 20181001 0 20180928
http restful 采用post方式,通过json body传入接口参数,请求地址为http://api.waditu.com
采用命令行工具curl的请求示例如下:
curl -X POST -d '{"api_name": "trade_cal", "token": "xxxxxxxx", "params": {"exchange":"", "start_date":"20180901", "end_date":"20181001", "is_open":"0"}, "fields": "exchange,cal_date,is_open,pretrade_date"}' http://api.waditu.com
返回结果:
{
"code":0,
"msg":null,
"data":{
"fields":[
"exchange",
"cal_date",
"is_open",
"pretrade_date"
],
"items":[
[
"SSE",
"20180901",
0,
"20180831"
],
[
"SSE",
"20180902",
0,
"20180831"
],
[
"SSE",
"20180908",
0,
"20180907"
],
...
[
"SSE",
"20180929",
0,
"20180928"
],
[
"SSE",
"20180930",
0,
"20180928"
],
[
"SSE",
"20181001",
0,
"20180928"
]
]
}
}