Ticker data error - connection was closed uncleanly (WebSocket connection upgrade failed

muruli10792
muruli10792 edited February 2022 in Python client
Hello,

i am trying to get the ticker data. Code is not returning any data. below is my code. please help.

Error message: ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))


request_token = "" # generate this before trading
api_key = ""
secret = ""
kite = KiteConnect(api_key=api_key)


data = kite.generate_session(request_token, secret)
kite.set_access_token(data["access_token"])
kt = KiteTicker(api_key,secret)
# Assign the callbacks.
def on_ticks(ws, ticks): # noqa
# Callback to receive ticks.
print("within on_ticks")
logging.info("Ticks: {}".format(ticks))
print(ticks)


def on_connect(ws, response): # noqa
# Callback on successful connect.
# Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
print("within on_connect")
ws.subscribe([738561, 5633])

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


def on_order_update(ws, data):
print("within on_order_update")
logging.debug("Order update : {}".format(data))

kt.on_ticks = on_ticks
kt.on_connect = on_connect
kt.on_order_update = on_order_update



# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kt.connect()
Sign In or Register to comment.