Default Python Client code for Websocket not working

mightymosquito
I copy pasted the sample in the docs as follows:

from kiteconnect import WebSocket

kws = WebSocket("XXXX", "XXXX", "XXXXX")

# Callback for tick reception.
def on_tick(tick, ws):
print tick

# Callback for successful connection.
def on_connect(ws):
# Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
ws.subscribe([738561, 5633])

# Set RELIANCE to tick in `full` mode.
ws.set_mode(ws.MODE_FULL, [738561])

# Assign the callbacks.
kws.on_tick = on_tick
kws.on_connect = on_connect

# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()

I just get the following output:


and the program exits.

There is no infinite loop as mentioned in the documentation.

Any help would be greatly appreciated.
  • Kailash
    Have you correctly installed the kiteconnect library using pip?
  • mightymosquito
    yes.

    this is what pip freeze looks like(in a virtualenv):
    backports.ssl-match-hostname==3.5.0.1
    kiteconnect==3.2
    pymongo==3.3.0
    requests==2.11.1
    six==1.10.0
    websocket-client==0.37.0
  • mightymosquito
    Just figured out the root url does not connect on wss://websocket.kite.trade/,

    Working fine with ws://websocket.kite.trade/
  • Kailash
    @mightymosquito 'ws' (insecure) is just a test endpoint and will be deprecated in the near future. if wss (secure / https) isn't working, there must be some issue with the root certificates on your system, which you should try and resolve.
Sign In or Register to comment.