Wasteland Wasteland - 3 months ago 22
Javascript Question

nodejs - filter live output

I'm trying to narrow down the live output of this nodejs script.

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();


The script is taken from an API documentation of an exchange:
https://poloniex.com/support/api/

When I run it in node, I get live updates of all currency pairs. How do I output only a selected pair?

I could not see anything like that in the documentation.

Answer
 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.
     }

I suggest casing on the first item of that array in ticker.