Ticks Callback

How many times in a trading day does the Ticks callback get triggered ? i need to execute some logic inside the Ticks callback. if the callback function is likely to get invoked every second then what happens to the callback function queued up in the stack after ticks stop coming?
  • sujith
    You need to use multi-threading, if you block the main thread then you will lose ticks.
    It can be called multiple times in a second as well.
  • MW5790
    @sujith i beliebe the nodejs client is single threaded. so if i put in some logic into the ticks callback, it will be queued during each invocation for execution. so there should be no blocking of the main thread ? i am trying to debug this and verify. NodeJs deosn't use multi threading ?
    the ticks callback is invoked each time a new tick is communicated by zerodha over the websocket. so its an event driven callback , where i don't control how many times I invoke the callback function . Tick appears --> invoke callback .
    Is my understanding right ?
  • sujith
    There is no queue in calling the callback. You will end up blocking the main thread. You may use promise or use asyc to do your stuff.
    You will have no control over the onTick callback. It is an event-driven mechanism.
  • MW5790
    when u say ticker.on("ticks", onTicks); and then in onTicks,
    function onTicks(ticks) {
    //logic here

    Are u suggesting that each invocation of onTicks that happens automatically throug the ticks event is not actually on a queue. if my logic takes say 10 secondss, the entire program is blocked for 10secs ?
  • rakeshr
    Are u suggesting that each invocation of onTicks that happens automatically through the ticks event is not actually on a queue?
    Yeah, logic in onTick event doesn't execute in the queue.
    if my logic takes say 10 seconds, the entire program is blocked for 10secs?
    Yeah, you are blocking onTick callback for 10 seconds/time required for your logic computation. You need to pass tick data from onTick to different async thread for required logic computation.
  • MW5790
    just to be clear, every time a tick happens, an event is triggered and my reigstered callback is invoked. now unitl my current invocation is completed, the next "Tick" event won't even get triggered.. am not abke to understand how I lose Ticks if my ticks handler takes say 10 sec for execution. can u explain the flow of how Zerodha emits events ?
  • MW5790
    similarly is this applicable for Order_Update call back also ?
  • MW5790
    I am trying to get a good entry for an Instrument based on last tick data. suppose I subscribe to 50 instruments On connect. then every tick I have to process 50 JSON objects in an array. in this case is it better to use the Python interface to setup multi threaded workers ? since NodeJs is ingerently single threaded ?
  • tonystark
    If you are comfortable with NodeJS then you can try worker threads. It does the same job in a safer way.

    But if you are doing heavy processing NodeJS might become the bottleneck. In that scenario, a language with better parallel processing capabilities will be a better choice.
  • RA7526
    just put ticks in a queue and then process them later. python implementation : https://gist.github.com/oldmonkABA/f73f5d67bcf85316ac0470919bf54e17
Sign In or Register to comment.