我想测试到binance wss://testnet-dex.binance.org/api/ws
的websocket连接。但是,每当我运行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"}}
好像我犯了错误,因为我写错了符号。但我使用了多个符号,它们都产生了相同的错误。不是说我只是复制/粘贴这个代码fron文档https://docs.binance.org/api-reference/dex-api/ws-streams.html
https://stackoverflow.com/questions/70735341
复制相似问题