Able to get holdings but not Ticks

DCAKV
I am trying to get the latest ticks for the holdings. As far as I understand the implementation should work but I'm not receiving ticks.
I'm able to get the holdings and no errors are generated in the logs however no logs as per ticks are printed on both server and client.

Angular Component:
  ngOnInit() {
this.socketService.observe('ticks').subscribe(console.log);
this.socketService.request('holdings').subscribe((holdings: Holding[]) => {
this.holdings = holdings;
});
}
Angular Service:
  request(type: string, data: any = {}) {
const observer = Observable.create((ob: Observer<any>) => {
// logged in user token, not access_token from zerodha
this.socket.on(`${type}-${this.user.token}-success`, (data: any) => ob.next(data));
}).pipe(take(1));
this.socket.emit(type, {...data, token: this.user.token});
return observer;
}
observe(type: string) {
return Observable.create((ob: Observer<any>) => {
this.socket.on(`${type}-${this.user.token}`, (data: any) => ob.next(data));
});
}
NodeJs Server:
  const listenWithZerodha = (eventName, process) => {
client.on(eventName, async (signal) => {
// ensure user is logged in and create app object
process(email, app, signal).then(
data => client.emit(`${eventName}-${signal.token}-success`, data),
err => client.emit(`${eventName}-${signal.token}-failure`, err));
});
};
listenWithZerodha('holdings', (email, app, {token}) => app.holdings().then((arr) => {
// not zerodha, but my app around zerodha
app.subscribe(arr.map((a) => a.instrument_token), (ticks) => {
console.log(ticks);
client.emit(`ticks-${token}`, ticks);
});
return arr;
}));
App implementation:
  async holdings() {
return this.connect.getHoldings();
}
subscribe(stocks, listener) {
this.ticker.connect();
this.ticker.subscribe(stocks);
this.ticker.setMode(this.ticker.modeFull, stocks);
this.ticker.on('ticks', (...params) => {
console.log(params);
listener(...params);
});
}
Please let me know if there is a issue in the above implementation.
Also please suggest how can I print zerodha ticker logs in console.
  • DCAKV
    DCAKV edited May 2022
    After some experimentation, I was able to get ticks by subscribing once connect is successful.
      subscribe(stocks, listener) {
    this.ticker.on('connect', () => {
    this.ticker.subscribe(stocks);
    this.ticker.setMode(this.ticker.modeFull, stocks);
    this.ticker.on('ticks', (...params) => {
    listener(...params);
    });
    });
    this.ticker.disconnect();
    this.ticker.connect();
    }
    This came as a surprise to me and that it does not throw connect trigger if already connected.
    Feel free to close this thread.
This discussion has been closed.