I am new to kite. I have been trying the github example of websocket usage in python since past 3 days. I have been setting the access token properly after generating every day. Subscribed to only one instrument in LTP mode. But every day after 3 hrs or so the connection gets aborted and ticks stop working. The logging is in debug mode. But this is the only error I get. DEBUG:root:Ticks: [{'tradable': True, 'mode': 'ltp', 'instrument_token': 408065, 'last_price': 1172.5}] DEBUG:root:Ticks: [{'tradable': True, 'mode': 'ltp', 'instrument_token': 408065, 'last_price': 1172.7}] ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (None) ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (None)
My internet connectivity is not an issue as I have been using internet all the while. Could someone please help resolve the issue.
I never get any ticks after this. Also it gets totally disconnected. Session ends abruptly after about 3hrs of running. It has been happening every time I try your example. I have been using MacBook Pro (Retina, 15-inch, Mid 2015), 2.2 GHz Intel Core i7 processor, 16 GB 1600 MHz DDR3 memory. Kindly look into the issue as I am really interested in using your platform for algo trading if the connection issue gets resolved.
@sujith I don't know why the code is not getting pasted. But I am just trying out the example given in zerodhatech/pykiteconnect for WebSocket usage. I have already mentioned this while filing the ticket. I just don't understand why are you asking this again. I tried your code line by line in ipython as well as from a python file. Every time after 3 hrs or so the connection gets aborted and ticks stop coming in. Please check.
def on_ticks(ws, ticks): # Callback to receive ticks. logging.debug("Ticks: {}".format(ticks))
def on_connect(ws, response): # Callback on successful connect. # 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 on_close(ws, code, reason): # On connection close stop the main loop ws.stop()
By default, websocket reconnects when it disconnects. Did you stop getting ticks after this?
Kindly look into the issue as I am really interested in using your platform for algo trading if the connection issue gets resolved.
Thanks.
how to print only last_price from websocket for python?
def on_ticks(ws, ticks):
for tick in ticks:
x=tick['last_price']
but websocket is not getting closed.
import logging
from kiteconnect import KiteTicker
logging.basicConfig(level=logging.DEBUG)
# Initialise
kws = KiteTicker("your_api_key", "your_access_token")
def on_ticks(ws, ticks):
# Callback to receive ticks.
logging.debug("Ticks: {}".format(ticks))
def on_connect(ws, response):
# Callback on successful connect.
# 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 on_close(ws, code, reason):
# On connection close stop the main loop
ws.stop()
# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()
My requirement is to check stock price at every second and if price is reached at certain level, I want to go with buy or sell.
If I dont use while loop and without ws.close(), kiteticker does not allow me do further operation for buy or sell.
You can check out this thread.