It looks like you're new here. If you want to get involved, click one of these buttons!
import pandas as pd
from kiteconnect import KiteTicker, KiteConnect
import logging
logging.basicConfig(level=logging.DEBUG)
access_token = "my_access_token"
api_key="my_api_key"
instruments = KiteConnect(api_key=api_key, access_token=access_token).instruments(exchange="NSE")
instruments= pd.DataFrame(instruments)
my_tokens= list(instruments[:500].instrument_token.astype(int))
kws = KiteTicker(api_key=api_key, access_token=access_token)
def on_ticks(ws, ticks):
logging.debug("1st row in Ticks: {}".format(ticks[0]))
def on_connect(ws, response):
ws.subscribe(my_tokens)
ws.set_mode(ws.MODE_FULL, my_tokens)
def on_close(ws, code, reason):
logging.info("Connection closed: {code} - {reason}".format(code=code, reason=reason))
def on_error(ws, code, reason):
logging.info("Connection error: {code} - {reason}".format(code=code, reason=reason))
def on_reconnect(ws, attempts_count):
logging.info("Reconnecting: {}".format(attempts_count))
def on_noreconnect(ws):
logging.info("Reconnect failed.")
kws.on_ticks = on_ticks
kws.on_close = on_close
kws.on_error = on_error
kws.on_connect = on_connect
kws.on_reconnect = on_reconnect
kws.on_noreconnect = on_noreconnect
kws.connect(threaded=True)
This step was successful.
my_tokens= list(instruments[:600].instrument_token.astype(int))
It was unsuccessful and I got the following error:
ERROR:kiteconnect.ticker:WebSocket connection lost: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
].
ERROR:kiteconnect.ticker:WebSocket connection lost: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
].
ERROR:kiteconnect.ticker:WebSocket connection lost: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
].
my_tokens= list(instruments[:500].instrument_token.astype(int))
In second process, everything was same but the instrument_tokens were selected with line below:
my_tokens= list(instruments[500:600].instrument_token.astype(int))
The first process was running fine and I was getting tickers, but I got the following error on the 2nd process:
INFO:root:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (429 - TooManyRequests))
INFO:root:Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (429 - TooManyRequests))
ERROR:kiteconnect.ticker:WebSocket connection lost: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionAborted'>: Connection was aborted locally, using.
].
INFO:root:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (429 - TooManyRequests))
INFO:root:Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (429 - TooManyRequests))
ERROR:kiteconnect.ticker:WebSocket connection lost: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionAborted'>: Connection was aborted locally, using.
].
ERROR:kiteconnect.ticker:Try reconnecting. Retry attempt count: 1
INFO:root:Reconnecting: 1
INFO:root:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (429 - TooManyRequests))
INFO:root:Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (429 - TooManyRequests))
ERROR:kiteconnect.ticker:WebSocket connection lost: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionAborted'>: Connection was aborted locally, using.
].
If you are facing new issues apart from anything mentioned in other thread then please create a new thread. Agree that Autobahn library is poorly documented but we made sure to reciprocate the error messages properly to the user. For example when rate limit applied you could see 429 error code in logs and 1009 error code which means maximum message length exceeded. None of the issue above mentioned was related to Autobahn implementation rather kite ticker backend quirk.
I would still say that from a user's perspective, your catching of errors in Autobahn is poor. Unfortunately it means we are having to delve into actual Autobahn codes.
The user shouldn't receive Autobahn error at all. Erorrs like Connection closed cleanly etc dont make sense.
All errors should be caught and wherever it is related to params set by you (say rate limit-1009 etc), user should get a simple error with the relevant details. Wherever it is originating out of Autobahn , you should still catch it and raise it as say GeneralException and then pass on the relevant autobahn error message. Why should user be handling Autobahn errors? It is not a common, popular library and websockets are complicated topics.
This approach gives practical, actionable errors to user while leaving them with flexibility to delve into Autobahn if they so desire.
In this case you compounded the problem by not testing it enough. Your server shouldn't have maxLength issues upto 1000 tickers under any scenario. How could it fail? Didn't you test and check you settings before rolling it out? Further, the 1009 error it threw was completely useless for a person who is coming through it for the first time. And then you switched off multiple connections abruptly not allowing users to have a workaround while they were coming to terms with 1009.
Short message is: Errors have to be graceful, and properly caught. Production systems have to be well tested before roll-out. Any changes in production systems have to be well publicized.
Else, you are setting up landmines for your users.
Regards
Saurav