efficient way to use tick data

which_part
how to use tick data at multiple places in monitoring many strategies positions?(as many of them having mtm stoploss)
i want to check positions prices on every tick without blocking on_tick function
For saving data and other processing i am using redis and celery . Saving data first to db and then retrieving from db to compare will make it slower
Any hint would be helpful
Thanks!
Tagged:
  • SRIJAN
    Then use the tick data to calculate pnl before dumping it into database.
  • which_part
    currently i am doing this
    lastPrice = {}
    def on_ticks(ws,ticks):
    for tick in ticks:
    lastPrice[tick['instrument_token']] = tick['last_price']

    def last_price():
    return lastPrice

    then check this dict in a while loop at multiple places
    is this non blocking and efficient or better approach possible?
    Thanks
  • SRIJAN
    SRIJAN edited August 2022
    It's not non-blocking.
    I mean not exactly,as it has to execute something!

    But it's pretty lightweight inside on_ticks,so I don't think you will get connection errors.
    I have used the same approach in the past,and I personally didn't have any problem.

    Although,I wasn't checking the dictionary, just saving it.

    If you get connection errors,you can go for the methods described here by Rakesh Sir.

    https://kite.trade/forum/discussion/comment/25535/#Comment_25535
  • which_part
    thanks!u may close the thread now
This discussion has been closed.