It looks like you're new here. If you want to get involved, click one of these buttons!
def initWebSocket(token, quote, subs):
print("Initializing web socket...", my_api_key, token[1], my_user_id)
# Initialise.
kws = WebSocket(my_api_key, token[1], my_user_id)
# Callback for tick reception.
def on_tick(ticks, ws):
print(ticks)
for tick in ticks:
quote[tick["instrument_token"]] = tick["last_price"]
print("TICK===>", tick["instrument_token"], tick["last_price"])
# Callback for successful connection.
def on_connect(ws):
print("On connect...", subs)
print("Is connected...", ws.is_connected())
# copying the list, otherwise gives a "Object of type 'ListProxy' is not JSON serializable"
subcopy = []
for s in subs:
subcopy.append(s)
print(s)
# Subscribe to a list of instrument_tokens
ws.subscribe(subcopy)
ws.set_mode(ws.MODE_LTP, subcopy)
# Assign the callbacks.
kws.on_tick = on_tick
kws.on_connect = on_connect
kws.enable_reconnect(reconnect_interval=5, reconnect_tries=50)
# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()
['BIOCON17AUGFUT']
You need to use instrument tokens while subscribing to the Kite ticker.
Kite ticker doesn't accept tradingsymbol.
Sometimes, kite object gives gateway error or invalid token / session error even if no other connection is made to Pi/NEST.
Reconnection is only for Kite Ticker.
If you log out of Kite then you will be logged out of Kite Connect also. Hence make sure not to log out of Kite.
I was referring to the Kite API (kiteconnect). Will the websocket help maintain connection to the kiteconnect as well?
Websockets with reconnection will help reconnection for Kite Ticker only.
Kite Connect API calls are HTTP APIs. Both are independent API end points.