hs-public
v0.0.3
Published
npm install hs-public
Downloads
7
Readme
HsPublic
npm install hs-public
##notice:
1.重写了错误处理逻辑 2.抽离对jquery ajax的依赖。成为一个独立的sdk 3.增加了对轮询的支持 4.代码上的优化 5.可能更多的功能,比如是否是开盘时间的判断等
##how to use
基本保证了api的兼容性,之前的代码基本不需要改动
但是tokenUrl变成配置项,使用前必须提供。不提供的话,运行不起来。一般会报错:Cannot read property 'isTokenValid' of null
HsDataFactoryList.configTokenServer({
tokenUrl:'http://your-token-url'
})
基本使用:
var client = HsDataFactoryList[clientType](
reqData,//参考恒生api
extraOptions // {loop:true,timeSpan:5000} 对轮询的支持
// loop:true 开启轮询
// timeSpan:5000//轮询的时间间隔,为最少时间间隔,如果不到,会等到5s,然后在请求。
).onDataReady(function(e){
//这里数据已经请求回来
}).onError(function(e){
//处理错误,一般使用者不需要处理。
//Token过期的错误,已经自动处理
}).on('tokenInvalid',function(){
//token过期时,触发,这时可以加快轮询时间等
client.timeSpan = 2000;
//正常后,轮询时间变正常
client.once('dataReady',function(){
client.timeSpan= 5000
})
}).init() //调用init后,请求才开始
client.stop()//停止轮询,已停止的化,没有作用
client.resume()//回复轮询,已经在轮询的,没有作用
目前支持的clientType
wizard:'http://open.hs.net/quote/v1/wizard',
kline:'http://open.hs.net/quote/v1/kline',
real:'http://open.hs.net/quote/v1/real',
trend:'http://open.hs.net/quote/v1/trend',
holiday:'http://open.hs.net/quote/v1/market/holiday',
sort:'http://open.hs.net/quote/v1/sort',
trend5day:'http://open.hs.net/quote/v1/trend5day
如果要添加,作为开发者可以去改代码(src/index.js里的apiUrlMap)
临时添加,可以使用(实验性功能)
HsDataFactoryList._apiUrlMap[newOne]='http://newOneApiUrl'
HsDataFactoryList._initApiUrl()
2.增加了对轮询的支持
var trend = HsDataFactoryList['trend'](
{
prod_code:'600570.SS',
fields:'last_px,avg_px,business_amount'
},
{
loop:true,//开启轮询
timeSpan:5000//轮询的时间间隔,为最少时间间隔,如果不到,会等到5s后在请求。
}
).onDataReady(function(e){console.log(e)})
.init();
##how to develop
if you have not installed gulp,babel at global env,first
npm i -g gulp
npm i -g babel
npm i
gulp dev-server
open http://localhost:8080/dev-demo/newApi.html
... to be continued