WebSocket - does it work for futures?

DS4769
Hi,

Does websockets work with futures?

I am passing instrument_token for a futures contract o subscribe but not getting any ticks.

The connect callback shows ws is connected.


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()


Thanks
  • DS4769
    The list passed to subscribe is
    ['BIOCON17AUGFUT']
  • sujith
    Hi,
    You need to use instrument tokens while subscribing to the Kite ticker.
    Kite ticker doesn't accept tradingsymbol.
  • DS4769
    Thanks, my bad.
  • DS4769
    Does the reconnect help with Kite connection as well?

    Sometimes, kite object gives gateway error or invalid token / session error even if no other connection is made to Pi/NEST.
  • sujith
    Hi,
    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.
  • DS4769
    Hi,

    I was referring to the Kite API (kiteconnect). Will the websocket help maintain connection to the kiteconnect as well?
  • sujith
    @DS4769,
    Websockets with reconnection will help reconnection for Kite Ticker only.
    Kite Connect API calls are HTTP APIs. Both are independent API end points.
Sign In or Register to comment.