It looks like you're new here. If you want to get involved, click one of these buttons!
websocketQuotes = {}
def updateQuotes(ticks):
global websocketQuotes
global instrument_symbol_dic
for tick in ticks:
tradingSymbol = instrument_symbol_dic[int(tick["instrument_token"])]
websocketQuotes[tradingSymbol] = tick
def on_ticks(ws, ticks):
updateOrdersSQL_thread = Thread(target=updateQuotes,args=(ticks,))
updateOrdersSQL_thread.start()
def on_connect(ws, response):
ws.subscribe([738561])
ws.set_mode(ws.MODE_FULL, [738561])
def on_close(ws, code, reason):
ws.stop()
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
kws.connect(threaded=True)
But ,it can't happen if you use 'stop' method as mentioned here:
https://github.com/zerodha/pykiteconnect#websocket-usage
https://github.com/zerodha/pykiteconnect/blob/20dbfd0152267b8da2a5afa17b737ca847b61814/kiteconnect/ticker.py#L342
If you want to just store quotes ,use threaded ticker,and call updateQuotes directly,rather than starting new thread for every tick.
Currently, according to my comparision. Quote is faster than Websocket by 0.3 second on an average. But in theory, it can't be. So probably my code is wrong.
https://kite.trade/forum/discussion/comment/25535/#Comment_25535
And as explained multiple times, it's impossible for market quotes to return a tick before websocket as quote API just fetches the latest tick from websocket. If a tick has not been streamed on the websocket,how will quote API fetch that tick, something that doesn't exist??
Yes @SRIJAN I understood, it is impossible. But my code is probably wrong, and somehow quote is fetching the results faster. I am sure, once I fix my code, websocket will be faster as expected.
The main difference here, I guess is. The quote is fetched from websocket on Kite server. But the websocket on my side is slower maybe? Since i did not implement it correctly.
Can you please try to run my code, and see, If "websocket" is able to outperform quote by comparing "last_trade_time"?
You just need to edit line 1 and 2, to use your own API. and u can just run the code and see the results.
Or you can just read the code and let me know, whats wrong.
https://drive.google.com/file/d/1vHALJQKxuFekIz90_sIClkSFWSfpvDJU/view?usp=sharing
Thanks a lot, appreciate it.
So,your observation that market quotes are faster than websocket ticks is just an illusion.
I am not understanding this example properly https://kite.trade/forum/discussion/comment/25535/#Comment_25535
Use python queue
Initial updateQuotes as thread in main program. And inside it you pass ticks to it via queue
And in the on_ticks method, you push ticks to this queue