Unable to connect websocket stream with python

menaveenn
Hi team,

I'm unable to connect to web socket stream with python.
below is my code:

from kiteconnect import WebSocket
kws = WebSocket(api_key, public_token_here, "RNXXX")

kws.is_connected() is returning false.

Note: I'm able to connect using kiteconnect and get the information and place orders.

Please do the needful.

Thanks,
Naveen
  • menaveenn
    Hi @vivek ,

    Any solution for this?

    Thanks,
    Naveen
  • Vivek
    @menaveenn It takes some time to establish a connection to Websocket so you have to use on_connect callback to wait for the connection to establish.
  • menaveenn
    @vivek thanks for your response,

    The reason for not connecting is _root = "wss://websocket.kite.trade/" value in web-socket class , after updating it to _root = "ws://websocket.kite.trade/" it is working fine.

    Now I'm getting the the streaming data but it is executing in infinite loop ,can you help me in how to break this loop after some time and store the values instead of printing ?

    Thanks,
    Naveen

  • menaveenn
    @vivek do you have any suggestions on this?

    your help on this would be highly appreciated.

    Thanks,
    Naveen

  • Vivek
    Vivek edited October 2016
    @menaveenn If you are using Ubuntu then there is a known issue with Open ssl.

    You should pass the param disable_ssl_verification=True to the .connect() method.

    The issue is due to a bug in OpenSSL itself -- https://github.com/liris/websocket-client/issues/35

    The actual solution would be to update OpenSSL itself.

    For reference check this thread - https://kite.trade/forum/discussion/comment/1431/
  • menaveenn
    Thanks for your response @vivek ,

    Can you help me in understanding below.

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

    Im able to see the streaming data now but its going infinite loop.

    How can store the streaming data and use it for mylogic as it is running in infinite loop ?
    Can you please help me in understanding "You have to use the pre-defined callbacks to manage subscriptions." so that I can change my code accordingly.


    Thanks,
    Naveen


  • Vivek
    When you start the server it runs in infinite loop and blocks the main thread just like a web server so you have to write logic in your on_tick callback function to store the data.

    If you would like to subscribe for more scrips on run time you can check this thread - https://kite.trade/forum/discussion/comment/1880/#Comment_1880
Sign In or Register to comment.