Web socket no response

raju.bn
raju.bn edited January 2017 in Python client
I have tried sample code given for websocket for python, but there was no tick data is coming.
I am using python 2.7 version.
  • Vivek
    @raju.bn I have tested with sample script and it seems to be working. Please check again with this script - https://gist.github.com/vividvilla/0d9fcaec1c02d65c4a429e43d55ae667
  • raju.bn
    raju.bn edited January 2017
    Hi Vivek,

    Please check this attached code for websocket, correct me if anything wrong.

    thx
    raju
  • raju.bn
    raju.bn edited January 2017
    from kiteconnect import WebSocket
    from imports import *

    class quote(threading.Thread):
    def __init__(self, api_key, public_token):
    threading.Thread.__init__(self)
    self.api_key = api_key
    self.public_token = public_token
    self.kws = WebSocket(self.api_key, self.public_token, "RN0684")
    # Assign the callbacks.
    self.kws.on_tick = self.on_tick
    self.kws.on_connect = self.on_connect

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

    # Callback for successful connection.
    def on_connect(self, 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])

    def run(self):
    while True:
    # Initialise.
    self.kws.connect()
    print ' Websocket is called'

  • raju.bn
    Yes its working fine now. Previous I have passed wrong public token.
This discussion has been closed.