【发布时间】:2023-01-04 14:05:07
【问题描述】:
我怎样才能从 binance web-socket 获得直播。有人知道吗?
我试过他的文档,但我无法正确理解 https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md#subscribe-to-a-stream 在他的文档链接上方
【问题讨论】:
标签: websocket cryptography binance
我怎样才能从 binance web-socket 获得直播。有人知道吗?
我试过他的文档,但我无法正确理解 https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md#subscribe-to-a-stream 在他的文档链接上方
【问题讨论】:
标签: websocket cryptography binance
试试这个文档 MarketStream
【讨论】:
有很多方法可以做到这一点,其中之一是以下示例:
const binanceSocket = new WebSocket("wss://stream.binance.com:9443/ws/!miniTicker@arr");
binanceSocket.onmessage = function (event) {
const messageObject = JSON.parse(event.data);
$("." + messageObject[0].s).html(messageObject[0].c);
messageObject.forEach(function (item, index) {
if (item.s === 'BTCUSDT') {
let btcValue = parseFloat(item.c);
$("#btcValue").html("BTC: $" + btcValue.toFixed(2));
}
});
}
【讨论】: