다음 코드는 다음과 같습니다. huobi는 약 5~6초 후에 서버의 핑을 받습니다. 그리고 나는 펑을 쏘아 올립니다. 하지만 서버는 펑을 받지 못하고 계속 핑을 쏘아 올리고 있습니다.
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()
}
}
(후오비에게 계속 펑을 보내서 반응이 없네요.) 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 정보 2019-03-21 00:30:23 정보 ok {“asks”:[[3.687,1684。。。。 2019-03-21 00:30:23 정보 ok {“asks”:[[3.687,1711,4640。。。