I am new to Python client for the Kite Connect trading API. I am using Ubuntu 14.04 LTS.
Installed Python client using pip install kiteconnect --upgrade --pre
pip show kiteconnect showing kiteconnect version 3.7.0b5
Today I ran the the official example (from github) of how to run KiteTicker in threaded mode through terminal. For the first run it produced desired output. But I terminated the program using Ctrl + C. After that whenever I am trying to run the official example, I am getting the following error:
INFO:root:This is main thread. Will change webosocket mode every 5 seconds. ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden)) INFO:root:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden)) ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden)) INFO:root:Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))
How to correct it and what is the correct way of closing the websocket connection cleanly?
@tanigai, The new Kite Ticker expects valid credentials for connecting to the ticker. If you see 403 then it means either api_key is invalid or access token is invalid.
I'm using the code to read the prices with the live streaming during market hours. While the order placement is possible, I'm unable to read the prices.
One of the differences I see between the two codes is that for live streaming, there is no place to provide the API secret. With the kite ticker, one can provide the API key as well is the session but there is no place to provide the API secret.
I'm using the version 3 and the date today is June 28, 2018
I am facing this same issue since last 2 days in a row.
The connection is closed with websocket error 1006.
Yesterday it closed at 1:56pm and today I got this error at 2:06pm.
I am running my code on Google cloud so internet connectivity or any other issue with the setup is out of question. The connection is closed from the zerodha server.
@PJ_2018 We don't close the Websocket streaming at our end. Websocket streaming connection will be closed if you are blocking the on_tick method by performing any calculation/activity inside.So, make sure that you offload all calculation to another thread from on_tick thread. You may check the threading example here.
There is absolutely no calculations/activities inside on_ticks as I am just fetching the ticks and have not coded any strategy yet. I was just testing my intial code set-up on Google cloud platform.
I have one simple question though on the below piece of code for on_close.
I have read in the documentation that "Auto reonnection is enabled by default and it can be disabled by passing reconnect param while initialising KiteTicker."
Although, the ws.close and ws.stop are commented out in the above code but if they are used inside on_close, would it stop websocket from trying to reconnect.
Also, please let me know how to override the default parameters for RECONNECT_MAX_TRIES, RECONNECT_MAX_DELAY and CONNECT_TIMEOUT.
Although, the ws.close and ws.stop are commented out in the above code but if they are used inside on_close, would it stop websocket from trying to reconnect.
Yeah, ws.stop() will terminate Websocket connection along with error message. So, if you are looking to re-connect, even in case of error,you need to remove ws.stop().
Also, please let me know how to override the default parameters for RECONNECT_MAX_TRIES, RECONNECT_MAX_DELAY and CONNECT_TIMEOUT.
You can override those params while initializing Websocket connection, check it here.
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))
even though i gave valid api key and access token
The new Kite Ticker expects valid credentials for connecting to the ticker. If you see 403 then it means either api_key is invalid or access token is invalid.
I'm having a similar problem. I'm using the code that is provided at this link:https://kite.trade/docs/pykiteconnect/v3/
I'm using the code to read the prices with the live streaming during market hours. While the order placement is possible, I'm unable to read the prices.
One of the differences I see between the two codes is that for live streaming, there is no place to provide the API secret. With the kite ticker, one can provide the API key as well is the session but there is no place to provide the API secret.
I'm using the version 3 and the date today is June 28, 2018
ticker:Connection error: 1006 - connection was closed uncleanly
Can you go through this thread?
Make sure, there is no assignment related error on_tick method.
The connection is closed with websocket error 1006.
Yesterday it closed at 1:56pm and today I got this error at 2:06pm.
I am running my code on Google cloud so internet connectivity or any other issue with the setup is out of question. The connection is closed from the zerodha server.
We don't close the Websocket streaming at our end.
Websocket streaming connection will be closed if you are blocking the on_tick method by performing any calculation/activity inside.So, make sure that you offload all calculation to another thread from on_tick thread. You may check the threading example here.
There is absolutely no calculations/activities inside on_ticks as I am just fetching the ticks and have not coded any strategy yet. I was just testing my intial code set-up on Google cloud platform.
I have one simple question though on the below piece of code for on_close.
kws.on_close = on_close
I have read in the documentation that "Auto reonnection is enabled by default and it can be disabled by passing reconnect param while initialising KiteTicker."
Although, the ws.close and ws.stop are commented out in the above code but if they are used inside on_close, would it stop websocket from trying to reconnect.
Also, please let me know how to override the default parameters for RECONNECT_MAX_TRIES, RECONNECT_MAX_DELAY and CONNECT_TIMEOUT.
Thanks.
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))
I have read the entire thread and I am passing a valid api_key and recent request token.
I am using the below code to connect to kiteticker
kws = KiteTicker(api_key,request_token)
tokens = [260105,256265] #token numbers of instruments
def on_ticks(ws, ticks):
logging.debug("Ticks: {}".format(ticks))
print(ticks)
def on_connect(ws, response):
# Subscribe to a list of instrument_tokens
ws.subscribe([260105,256265])
ws.set_mode(ws.MODE_FULL,[260105])
def on_close(ws, code, reason):
# On connection close stop the main loop
# Reconnection will not happen after executing `ws.stop()`
ws.stop()
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
kws.connect()
sorry found spelling mistake