Wasteland Wasteland - 1 year ago 220
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) {
function tickerEvent (args,kwargs) {
function trollboxEvent (args,kwargs) {
session.subscribe('BTC_XMR', marketEvent);
session.subscribe('ticker', tickerEvent);
session.subscribe('trollbox', trollboxEvent);

connection.onclose = function () {
console.log("Websocket connection closed");


The script is taken from an API documentation of an exchange:

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 Source
 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download