我试图缩小此nodejs脚本的实时输出。
var autobahn = require('autobahn');
var wsuri = "wss://api.poloniex.com";
var connection = new autobahn.Connection({
url: wsuri,
realm: "realm1"
});
connection.onopen = function (session) {
function marketEvent (args,kwargs) {
console.log(args);
}
function tickerEvent (args,kwargs) {
console.log(args);
}
function trollboxEvent (args,kwargs) {
console.log(args);
}
session.subscribe('BTC_XMR', marketEvent);
session.subscribe('ticker', tickerEvent);
session.subscribe('trollbox', trollboxEvent);
}
connection.onclose = function () {
console.log("Websocket connection closed");
}
connection.open();
该脚本取自交换的API文档: https://poloniex.com/support/api/
当我在节点中运行它时,我会获得所有货币对的实时更新。如何仅输出所选对?
我在文档中看不到类似内容。
答案 0 :(得分:1)
function tickerEvent (args,kwargs) {
if(args[0] !== "BTC_SDC"){
return; // causes anything not "BTC_SDC" related to be filtered out.
}
console.log(args); // information you want.
}
我建议在自动收报机中对该数组的第一项进行套接。