下面介绍两种常用的数据调取方式:
1、已经获取到datacube token凭证 【注册用户】
2、已经安装好python环境
安装Python包
pip install dcube
导入datacube
import dcube as dc
用token初始化pro接口
pro = dc.pro_api('your token')
数据调取
以获取交易日历信息为例:
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传入接口参数,请求地址为datacubeapi.foundersc.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://datacubeapi.foundersc.com
返回结果:
```json
{
"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"
]
]
}
}```