Is kite quote faster than websocket?

KesharDev
My algorithm needs to fetch prices 5-10 times during the first minute of market open at unfixed intervels (09:15).

For example fetch lastest prices at 09:15:15, 09:15:23, 09:15:25, 09:15:44 etc....


According to my code kite.quote() is faster.

I tested the speed of kite quote and websocket using the "timestamp" value. This is the code which I used.

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)

socketSlowTime = 0
for i in range(100):
quoteTime = kite.quote("NSE:RELIANCE")["NSE:RELIANCE"]["timestamp"]
socketTime = websocketQuotes["RELIANCE"]["timestamp"]
delay = (quoteTime-socketTime).seconds
socketSlowTime += delay
time.sleep(0.1)
print("socket total delay time is",socketSlowTime,"seconds")

The output was:

socket total delay time is 33 seconds
Tagged:
  • sujith
    Quote API fetches data from Websocket stream only. If you don't need data every second or few seconds then you can go for Quote API. If you need data more frequently then use Websocket API.
Sign In or Register to comment.