Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake) unable to recieve tick, is there any change is the system
Getting Error in the Twisted library python , i am using the threaded mode there is error in format coming from server please check i have tested with other api keys but still same issue @rakeshr
File "/home/dknaix/.local/lib/python3.11/site-packages/autobahn/twisted/websocket.py", line 322, in _onMessage self.onMessage(payload, isBinary) File "/home/dknaix/.local/lib/python3.11/site-packages/kiteconnect/ticker.py", line 71, in onMessage self.factory.on_message(self, payload, is_binary) File "/home/dknaix/.local/lib/python3.11/site-packages/kiteconnect/ticker.py", line 679, in _on_message self.on_ticks(self, self._parse_binary(payload)) builtins.KeyError: 256265
after trying to subscribe to nifty ws.set_mode(ws.MODE_FULL, [256265])
File "/home/dknaix/.local/lib/python3.11/site-packages/autobahn/twisted/websocket.py", line 322, in _onMessage
self.onMessage(payload, isBinary)
File "/home/dknaix/.local/lib/python3.11/site-packages/kiteconnect/ticker.py", line 71, in onMessage
self.factory.on_message(self, payload, is_binary)
File "/home/dknaix/.local/lib/python3.11/site-packages/kiteconnect/ticker.py", line 679, in _on_message
self.on_ticks(self, self._parse_binary(payload))
builtins.KeyError: 256265
after trying to subscribe to nifty
ws.set_mode(ws.MODE_FULL, [256265])
# Initialize KiteConnect object with API key
api_key = "token"
access_token = "accesstoken"
kite = KiteConnect(api_key=api_key)
# Set the access token
kite.set_access_token(access_token)
# Define the instrument token (example: Nifty 50)
instrument_token = "256265" # Replace with the actual instrument token you want to subscribe to
# Callback to handle the real-time data
def on_ticks(ws, ticks):
""" On receiving live market data """
print("Ticks: {}".format(ticks))
# Callback to handle connection status
def on_connect(ws, response):
""" On successful connection """
print("Connected successfully")
ws.subscribe([instrument_token]) # Subscribe to instrument token
print("done")
# Callback to handle disconnection
def on_close(ws, code, reason):
""" On websocket close """
print("Connection closed: Code={}, Reason={}".format(code, reason))
# Create KiteTicker object
kite_ticker = KiteTicker(api_key, access_token)
# Assign the callbacks
kite_ticker.on_ticks = on_ticks
kite_ticker.on_connect = on_connect
kite_ticker.on_close = on_close
# Infinite loop to keep the script running
print("Starting the WebSocket...")
kite_ticker.connect(threaded=True)
this code is also not running getting the following error
Connection error: 0 - error parsing request