It looks like you're new here. If you want to get involved, click one of these buttons!
function startWebSocket (api_key, user_id, public_token){
console.log("-----inside function startWebSocket------");
check(api_key,String);
check(user_id, String);
check(public_token, String);
let KiteTicker = require("kiteconnect").KiteTicker;
let ticker = new KiteTicker(api_key, user_id, public_token);
console.log("-----Getting ticker started ------");
console.log(ticker);
console.log("-----starting the Ticker ------");
ticker.connect();
console.log("Ticker connected: "+ticker.connected());
ticker.on("tick", logTick);
ticker.on("connect", onTickerSubscribe);
ticker.on("unsubscribe", onTickerUnSubscribe);
ticker.on("disconnect", onTickerDisconnet);
function logTick(ticks) {
console.log("-----recieved quote ------");
console.log("Ticks", ticks);
}
function onTickerSubscribe() {
console.log("Ticker connected: "+ticker.connected());
console.log("-----Subscribing to WS ------");
let items = [11654402];
ticker.subscribe(items);
ticker.setMode(ticker.modeLTP, items);
}
function onTickerUnSubscribe(){
console.log("-----Ticker Unsubscribed ------");
console.log("Ticker connected: "+ticker.connected());
}
function onTickerDisconnet () {
console.log("-----Ticker Disconnected ------");
console.log("Ticker connected: "+ticker.connected());
}
}
The logs from the server:
I20170218-07:42:01.999(5.5)? ------REcieved the response from Zerodha server--------
I20170218-07:42:02.005(5.5)? -----inside function startWebSocket------
I20170218-07:42:02.007(5.5)? -----Getting ticker started ------
I20170218-07:42:02.019(5.5)? { modeFull: 'full',
I20170218-07:42:02.019(5.5)? modeQuote: 'quote',
I20170218-07:42:02.020(5.5)? modeLTP: 'ltp',
I20170218-07:42:02.021(5.5)? autoReconnect: [Function],
I20170218-07:42:02.021(5.5)? connect: [Function],
I20170218-07:42:02.022(5.5)? disconnect: [Function],
I20170218-07:42:02.022(5.5)? connected: [Function],
I20170218-07:42:02.022(5.5)? on: [Function],
I20170218-07:42:02.023(5.5)? subscribe: [Function],
I20170218-07:42:02.024(5.5)? unsubscribe: [Function],
I20170218-07:42:02.025(5.5)? setMode: [Function] }
I20170218-07:42:02.027(5.5)? -----starting the Ticker ------
I20170218-07:42:02.028(5.5)? Ticker connected: false
I20170218-07:42:03.174(5.5)? Ticker connected: true
I20170218-07:42:03.175(5.5)? -----Subscribing to WS ------
I20170218-07:42:33.173(5.5)? -----Ticker Disconnected ------
I20170218-07:42:33.174(5.5)? Ticker connected: false
I20170218-07:42:38.199(5.5)? -----Ticker Disconnected ------
I20170218-07:42:38.200(5.5)? Ticker connected: false
Will appreciate any help.
You should subscribe inside onConnected() not OnSubscribed().
I cant find the onConnected() in the kiteconnectjs documentation, but if you were referring to my code; i have modified it as per your recommendation here: still the same results:
We just copy pasted your code and changed instrument token to liquid scrip. Above code works fine.
try 738561
psst.. I am behind a firewall currently, does that have an affect on this?
It could. We tried your exact same code and it was working for us. Can you try in different network?
While debugging i found out that the Binary data was coming in the form of 'MessageEvent.data' which had 'Blob' type but in the kiteconnectjs the code is checking for 'ArrayBuffer'. I think this might be an issue.
is this by design?.. if yes please suggest what else I can do?
I didn't understand . Can you elaborate?
Any relations, you think?
You get binary data there, it is array of bytes. It is not blob. You can check out more information about packet structure here. I don't think you should be making any changes there.
currenlty i am trying to figure out how to debug the nodejs code in the server side. only then can i really be sure.
I have just reconfigured the vanila websocket on the server, and still the kite connect websocket does not give any response, except the heartbeat.
has anyone else used kiteconnect nodejs client on server till date? if yes, can you please share your code?
Regards
Arsh