Comments (5)
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.
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.
you should await datafeed.connectSocket()
before subscribing
from kucoin-node-sdk.
The demo does not show any await before subscribing
from kucoin-node-sdk.
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)
- How do I sign requests? HOT 4
- Config file - SyntaxError: Unexpected token : HOT 1
- getAllTickers() is only returning a total of 14 tickers. HOT 1
- Several wallet address for one coin
- applyWithdraw empty result, no action
- Shared config object HOT 3
- Api support for robots?
- PageSize HOT 2
- websocket message type is wrong HOT 2
- Catching "Too many request" error
- Getting empty data for orders list api
- Getting empty JSON response from getAccountList, getAccountInformation, getSubUsers
- Websocket ticker_demo.js not working
- typescript types
- typescript HOT 1
- Cannot destructure property 'instanceServers' of 'server' as it is undefined.
- How do I get response headers of rate limit?
- V3 API dont work HOT 2
- Can not install latest HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kucoin-node-sdk.