KiteTicker ticks related query

nkotwar
If on_ticks() function takes longer time to execute than time between 2 ticks, is it possible to lose out on some ticks?
  • SRIJAN
    It won't happen unless there is network error or you do computations inside on_ticks. But when it happens, websocket will close connection.
  • nkotwar
    nkotwar edited January 2022
    @SRIJAN I am planning to do few computations and even place order inside on_ticks, is there any way around that to avoid mentioned problem?
    P.S. assume ideal network connection
  • vijoeyz
    Use multithreading, and start ticker in the threaded mode.
  • nkotwar
    @SRIJAN @vijoeyz Appreciate your responses, helped me a lot.
    I looked up about threading, and it's very fascinating, although I do have one query:

    Ques: even if I use a different thread to perform calculations (and possibly place order), (refer this), won't I face disconnections as SRIJAN mentioned
    "websocket will close connection" when I perform time taking calculations in some helper function getting called from on_ticks() in a different thread?
    what I'm trying to ask is, in below attached code (by @rakeshr ), will helper_method gets called asynchronously? or are we still open to websocket disconnections if helper method takes more time to execute than time between ticks?

    while True:
    #Perform required data operation using tick data
    def on_ticks(ws, ticks):
    ..........
    helper_method(ticks)
    .........

    def helper_method(ticks):
    .........
    Perform computation here
    ........
    #Assign callback
    kws.on_ticks=on_ticks

    *ignore indentation errors*

    I understand you are not obligated to help, but any hints are appreciated.
  • SRIJAN
    SRIJAN edited January 2022
    @nkotwar Read this properly,https://kite.trade/forum/discussion/comment/25535/#Comment_25535
    Multithreading methods are asynchronous.
  • nkotwar
    @SRIJAN That was my only concern, thanks for clearing up : ))
  • vijoeyz
    When you do:
    kws.connect(threaded=True)
    a new thread is started, and the original thread returns to the caller. All registered callbacks are invoked in the WebSocket's context.

    Although in Python, multi-threading is not truly multi, because of the Global Interpreter Lock, but the threaded mode does help.
Sign In or Register to comment.