Tether
USDT
1,195.0
-0.17%
var wsUri = "wss://cu-api.com/cuws"; let websocket = null; function init() { testWebSocket(); } let dataList = null; function testWebSocket() { websocket = new WebSocket(wsUri); websocket.onopen = function (evt) { // 12823153 var data = { 'op': 'auth', 'args': '[email protected]#$', 'username': '' } websocket.send(JSON.stringify(data),res=>{ console.log("发送",res); }) }; websocket.onclose = function (evt) { console.log("关闭",evt); }; websocket.onmessage = function (evt) { let data = JSON.parse(evt.data); onMessage(data);//数据 }; websocket.onerror = function (evt) { // console.log("报错",evt); setTimeout(()=>{ testWebSocket() },5000) }; } function onClose(evt) { websocket.close(); } function onMessage(evt) { if(evt){ evt.forEach((v,i) => { if(v.data.p == 'USDT'){ dataList = v.data; document.getElementById('price-2').innerText = dataList.a; document.getElementById('price').innerText= (dataList.a-dataList.c) / dataList.c; document.getElementById('price').style.color=((dataList.a-dataList.c) / dataList.c)>0?'green':'red' } }); } } init();