Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Add option to Datafeed class to enable specific topics#26

Open
Azurethi wants to merge 1 commit intoKucoin:masterfrom
Azurethi:master
Open

Add option to Datafeed class to enable specific topics#26
Azurethi wants to merge 1 commit intoKucoin:masterfrom
Azurethi:master

Conversation

@Azurethi
Copy link
Copy Markdown

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant