Websocket 连接到 binance api returns 错误
Websocket connection to binance api returns error
我想测试 websocket 与 binance 的连接 api wss://testnet-dex.binance.org/api/ws
。
但是每当我 运行 js 脚本时,我都会收到来自 ws
.
的错误响应
脚本看起来像那样
const WebSocket = require('ws');
const conn = new WebSocket("wss://testnet-dex.binance.org/api/ws");
conn.onopen = function(evt) {
conn.send(JSON.stringify({ method: "subscribe", topic: "trades", symbols: ["ETH_BNB"] })); // I did try using as an symbols 'BNB_USDT.B-B7C', but got the same error
}
conn.onmessage = function(evt) {
console.info('received data', evt.data);
};
conn.onerror = function(evt) {
console.error('an error occurred', evt.data);
};
只要脚本是运行,我就会
received data {"method":"subscribe","error":{"error":"Invalid symbol(s)"}}
received data {"method":"subscribe","error":{"error":"Symbols [BNB_USDT.B-B7C] are not valid for topic: trades, for user: 100.x.x.x:3333 \u003e 100.xx.x.x:59558"}}
我似乎出错了,因为我确实写错了符号。但是我使用了多个符号,它们都产生了相同的错误。并不是说我只是 copy/paste binance 文档中的这段代码 https://docs.binance.org/api-reference/dex-api/ws-streams.html
我想测试 websocket 与 binance 的连接 api wss://testnet-dex.binance.org/api/ws
。
但是每当我 运行 js 脚本时,我都会收到来自 ws
.
脚本看起来像那样
const WebSocket = require('ws');
const conn = new WebSocket("wss://testnet-dex.binance.org/api/ws");
conn.onopen = function(evt) {
conn.send(JSON.stringify({ method: "subscribe", topic: "trades", symbols: ["ETH_BNB"] })); // I did try using as an symbols 'BNB_USDT.B-B7C', but got the same error
}
conn.onmessage = function(evt) {
console.info('received data', evt.data);
};
conn.onerror = function(evt) {
console.error('an error occurred', evt.data);
};
只要脚本是运行,我就会
received data {"method":"subscribe","error":{"error":"Invalid symbol(s)"}}
received data {"method":"subscribe","error":{"error":"Symbols [BNB_USDT.B-B7C] are not valid for topic: trades, for user: 100.x.x.x:3333 \u003e 100.xx.x.x:59558"}}
我似乎出错了,因为我确实写错了符号。但是我使用了多个符号,它们都产生了相同的错误。并不是说我只是 copy/paste binance 文档中的这段代码 https://docs.binance.org/api-reference/dex-api/ws-streams.html