Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to Datafeed class to enable specific topics #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Azurethi
Copy link

Updates the constructor of the Datafeed class in src/lib/datafeed.js to take an additional Boolean parameter which defaults to false for backward compatibility.

When true, this enables "specific topics", where the topic listeners are added without taking the the prefix of their respective topic. This eliminates the usual check for each topic in the example below. I feel this is much more in line with the expected behaviour of Datafeed.subscribe(topic, hook) and definitely saves me a few lines when using the library.

It may be an idea in future to allow the creation of hooks which listen to multiple topics, however it would make more sense to have a separate set of functions for this.

const kucoin = require('kucoin-node-sdk');

//Creating a new feed with the new specific parameter set true
let feed = new kucoin.websocket.Datafeed(false, true);

//typical datafeed setup
feed.connectSocket();
feed.onClose(()=>{console.log("datafeed closed");}

feed.subscribe('/market/match:BTC-USDT', msg=>{
  if(msg.topic === '/market/match:BTC-USDT') return; // no longer nessesary when specific=true
  
  //do stuff...
  
});

feed.subscribe('/market/match:ETH-USDT', msg=>{
  if(msg.topic === '/market/match:ETH-USDT') return; // no longer nessesary when specific=true
  
  //do stuff...
  
});

- removes need for topic check in listeners
- defaults to false for backwards compatability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant