一 接口描述
获取当前行情
1. 接口地址:/open/api/get_ticker
2. 接口说明:(get请求)获取当前行情
* 该接口不进行签名校验
参数 | 填写类型 | 说明 |
---|---|---|
symbol | 必填 | 市场标记,btcusdt,详情看下面 |
返回值:
字段 | 实例 | 解释 |
---|---|---|
code | 0 | |
msg | "suc" | code>0失败 |
data | 如下: |
{
"high": 1,//最高值
"vol": 10232.26315789,//交易量
"last": 173.60263169,//最新成交价
"low": 0.01,//最低值
"buy": "0.01000000",//买一价
"sell": "1.12345680",//卖一价
"rose": -0.44564773,//涨跌幅
"time": 1514448473626
}
二 java实现
public static double getUnitPriceByNameFromcBIKI(String name) throws Exception {
//获取美元价格
String url = "https://openapi.bikicoin.pro/open/api/get_ticker?symbol=" + name;
String body = Jsoup.connect(url).ignoreContentType(true).execute().body();
JSONObject obj = JSONObject.parseObject(body);
Integer Code = obj.getInteger("code");
if ( 0 == Code) {
JSONObject jsonObjectData= obj.getJSONObject("data");
Double sellPrice = jsonObjectData.getDouble("sell");
return sellPrice;
} else {
return Double.NaN;
}
}
三 总结
1 使用爬虫库Jsoup,进行get网络请求
https://jsoup.org/
2 使用fastJson解析json https://github.com/alibaba/fastjson/wiki
3 bikiapi文档
https://bikicoin.oss-cn-hangzhou.aliyuncs.com/web_doc/openapi.pdf
https://support.biki.com/hc/zh-cn/articles/360015256351-API%E6%96%87%E6%A1%A3
网友评论