I am trying to find a way to get all strikes of particular index (Nifty, Bank Nifty, Sensex, Fin Nifty, Bank Ex) with ltp for particular expiry in less than 2 - 5 sec.
I tried with kite.ltp way to get it done But it is taking more than 3 min to get all strikes and ltp's.
Can you please suggest the other way to get this ?
One last question on this thread, I need to stop socket streaming completely once all tokens are done from data fetching. I see above ws.unsubscribe([tokens]) is stopping the subscription for tokens But, still socket streaming is open and continuing.
I have gone through above links and got the answer and it worked as well. When i try to run second time same code I am facing this error "ReactorNotRestartable"
When I close and re-open the spyder and run then it is working.
1. Try DB then fetch
2. Try native dictionary then fetch
Quote ltp is a snap of WebSocket so You will not get data at the exact time you require. kite.ltp is an inefficient way to fetch data.
You can check Ws for more information: https://kite.trade/docs/connect/v3/websocket/
Ok, I tried using web socket and getting the required details. But, I would like to stop streaming once I receive data for all strikes in the list.
May I know how to achieve this ?
ws.unsubscribe([tokens])
You can check detail explanation: https://kite.trade/forum/discussion/comment/19217/#Comment_19217
Thanks a lot !
One last question on this thread, I need to stop socket streaming completely once all tokens are done from data fetching.
I see above ws.unsubscribe([tokens]) is stopping the subscription for tokens But, still socket streaming is open and continuing.
kws.stop()
Check out for more details: https://github.com/zerodha/pykiteconnect/tree/7df83ddcdbd5f74b4be6ae558b3b6a6dbfe05d94
& https://kite.trade/forum/discussion/12649/clean-way-to-stop-close-kite-websocket-connection
I have gone through above links and got the answer and it worked as well.
When i try to run second time same code I am facing this error "ReactorNotRestartable"
When I close and re-open the spyder and run then it is working.
Here is my code -
def on_ticks(ws, ticks):
# Callback to receive ticks.
logging.info("Ticks: {}".format(ticks))
ws.unsubscribe([46256])
def on_connect(ws, response):
# Callback on successful connect.
ws.subscribe([46256])
ws.set_mode(ws.MODE_LTP, [46256])
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()
try:
kws.connect(threaded=True)
except Exception as e:
print(f"Connection closed uncleanly: {e}")
time.sleep(30)
kws.close()
Can you please guide to fix this issue ?
Go through the python websocket FAQs here.
Please find the details in below github page.
https://gist.github.com/tradervishnuvardhan/20512e0f5ff79a92e7356233214717fb
I have fixed the issue, Thanks !