Giter VIP home page Giter VIP logo

Comments (5)

ne0c0de avatar ne0c0de commented on July 24, 2024 1

this is what I'm trying to do in last 1 hour,

after diving in datafeed.js I noticed that we need to send some additional parameters:

while initializing datafeed you should initialize like this:

const datafeed = new kucoin.websocket.Datafeed(true);

and you need to subscribe topic like this:

    setTimeout(function(){
        const topic = '/spotMarket/tradeOrders'
        const callbackId = datafeed.subscribe(topic, (message) => {
            if (message.topic === topic) {
                console.log(new Date(), message.data)
            }
        }, true);
        console.log(`subscribe id: ${callbackId}`);
    }, 5000)

I suggest you to use setTimeout for subscribing because it takes few seconds to get private bullet for websocket

from kucoin-node-sdk.

codewc avatar codewc commented on July 24, 2024

this is what I'm trying to do in last 1 hour,

after diving in datafeed.js I noticed that we need to send some additional parameters:

while initializing datafeed you should initialize like this:

const datafeed = new kucoin.websocket.Datafeed(true);

and you need to subscribe topic like this:

    setTimeout(function(){
        const topic = '/spotMarket/tradeOrders'
        const callbackId = datafeed.subscribe(topic, (message) => {
            if (message.topic === topic) {
                console.log(new Date(), message.data)
            }
        }, true);
        console.log(`subscribe id: ${callbackId}`);
    }, 5000)

I suggest you to use setTimeout for subscribing because it takes few seconds to get private bullet for websocket

You can try with the following code.

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

const config = require('./config');
API.init(require('./config'))


// ws demo
const datafeed = new API.websocket.Datafeed(privateBullet = true);

// close callback
datafeed.onClose(() => {
  console.log('ws closed, status ', datafeed.trustConnected);
});
// connect
datafeed.connectSocket();

// subscribe
const topic = `/spotMarket/tradeOrders`;
const callbackId = datafeed.subscribe(topic, (message) => {
    console.log(JSON.stringify(message.data));
}, true);

console.log(`subscribe id: ${callbackId}`);

from kucoin-node-sdk.

TomKaltz avatar TomKaltz commented on July 24, 2024

you should await datafeed.connectSocket() before subscribing

from kucoin-node-sdk.

PhatJay76 avatar PhatJay76 commented on July 24, 2024

The demo does not show any await before subscribing

from kucoin-node-sdk.

abd777 avatar abd777 commented on July 24, 2024

You can watch for datafeed.trustConnected if it's true , it means the connection has been established

Watcher function can be something like that

function watchForConnection(success) { const interval = setInterval(() => { console.log(datafeed.trustConnected); if (datafeed.trustConnected) { clearInterval(interval); success(); } }, 100); }
and the use it

watchForConnection(() => { console.log("here we go "); });

from kucoin-node-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.