okex 거래소 websocket blob 데이터 처리방법
<script src="https://cdn.jsdelivr.net/pako/1.0.3/pako.min.js"></script>
<script>
var pako = window.pako;
//https://api.okex.co.kr/kr/docs/webSocketAPI/webSocketAPI
var okexSocket = new WebSocket("wss://real.okex.com:8443/ws/v3");
okexSocket.binaryType = 'arraybuffer';
//okexSocket.binaryType = 'blob';
okexSocket.onopen = function(){
setInterval(function(){
//console.log('okex ping');
okexSocket.send('ping');
}, 10000);
//okexSocket.send('{"op": "subscribe", "args": ["spot/ticker:BTC-USDT","spot/candle60s:BTC-USDT"]}');
//okexSocket.send('{"op": "subscribe", "args": ["spot/trade:BTC-USDT"]}');
okexSocket.send('{"op": "subscribe", "args": ["spot/ticker:BTC-KRW","spot/candle60s:BTC-KRW"]}');
};
okexSocket.onmessage = function(evt){
//https://github.com/nodeca/pako
//console.log(evt);
var arr = new Uint8Array(evt.data);
var resultAsBinString = pako.inflateRaw(arr, { to: 'string' });
console.log(resultAsBinString);
if(resultAsBinString != 'pong')
{
var data = JSON.parse(resultAsBinString);
console.log(data);
}
};
</script>