0
Follow
0
Followers
hbdm和ok合约同时用websocket,huobi发出去pong没反应
Created 2019-03-21 00:35:45 Updated 2019-03-21 11:26:42
8
3648
代码如下,huobi在大概五六秒之后,会收到服务器的ping,然后我会发出一个pong,但是一直好像服务器收不到Pong似的,还在一直给我发ping,请教了大神说是给read加-1,但加了还是没用
function main() {
var ws_hbdm = Dial("wss://www.hbdm.com/ws?compress=true|compress=gzip&mode=recv")
var ws_ok= Dial("wss://real.okex.com:10440/ws/v1?compress=true|compress=gzip_raw&mode=recv")
var pingCyc = 1000 * 120
var lastPingTime = new Date().getTime()
if(ws_hbdm && ws_ok){
ws_hbdm.write('{"sub": "market.EOS_CW.depth.step6","id": "id2"}')
ws_ok.write("{'event':'addChannel','channel':'ok_sub_futureusd_eos_depth_this_week_5'}")
while(1){
//读取huobi数据
var ret = ws_hbdm.read(-1)
if(ret){
var ret1=JSON.parse(ret)
if("tick" in ret1){
Log("huobi",ret1.tick)
}else if("ping" in ret1){
ws_hbdm.write('{"pong":'+parseInt(ret1.ping)+'}')
Log("pong")
}
}
//读取ok数据
var nowTime = new Date().getTime()
var ret2 = ws_ok.read(-1)
if(ret2){
if(nowTime - lastPingTime > pingCyc){
ws_ok.write("{'event':'ping'}")
lastPingTime = nowTime
}
var ret3=JSON.parse(ret2)
if(ret3.length>0){
if("data" in ret3[0]){
Log("ok",ret3[0].data)
}
}
}
}
//ws_hbdm.close()
}
}
日志如下: (一直给huobi发pong值,就是没反应)
2019-03-21 00:30:25 信息 ok {"asks":[[3.687,18。。。。
2019-03-21 00:30:24 信息 ok {"asks":[[3.687,1684。。。。
2019-03-21 00:30:24 信息 pong
2019-03-21 00:30:23 信息 ok {"asks":[[3.687,1684。。。。
2019-03-21 00:30:23 信息 ok {"asks":[[3.687,1711,4640。。。
Related Recommendations
Event-Driven Backtesting with Python - Part IVEvent-Driven Backtesting with Python - Part IIIEvent-Driven Backtesting with Python - Part IIEvent-Driven Backtesting with Python - Part ISuccessful Backtesting of Algorithmic Trading Strategies - Part IISuccessful Backtesting of Algorithmic Trading Strategies - Part IValue at Risk (VaR) for Algorithmic Trading Risk ManagementShould You Build Your Own Backtester?Money Management via the Kelly CriterionSharpe Ratio for Algorithmic Trading Performance Measurement
Comment
All comments (8)
是的,我收到Ping的检查之后,马上回复pong,xxx.read() 这样读到之后返回pong是可以的,xxx.read(-1)这样就不可以了,不知道原因
7 years ago
如代码,我想同时获取OK和火币的行情数据,OK可以一直收到行情数据,但火币过了5秒之后就收不到了(我也回应了ping),所以想让帮忙看看代码,找找原因,我找了两天了
7 years ago
- 1

