connection closed:1006

Ashok121
Ashok121 edited July 2018 in Python client
Hi,
My python code was running successfully for last few days but today I got following error:

ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
ERROR:kiteconnect.ticker:Connection closed: 1006 - connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)


When I re-run the same after sometime, it started successfully. But i missed today's trade and also lost good amount of profit.

My python code as follows:
{
from kiteconnect import KiteConnect
api_key=open('api_key.txt','r').read()
api_secret=open('api_secret.txt','r').read()
kite=KiteConnect(api_key=api_key)
kite.set_access_token(open('access_token.txt','r').read())
import datetime
import os
import time
os.environ["TZ"] = "Asia/Kolkata"
time.tzset()
import logging
from kiteconnect import KiteTicker
access_token=(open('access_token.txt','r').read())
logging.basicConfig(level=logging.DEBUG)
kws = KiteTicker("my api key",access_token)
from time import sleep
import time
import xlrd
workbook = xlrd.open_workbook('LP.xls')
worksheet = workbook.sheet_by_index(1)
H2=round(worksheet.cell(10, 14).value)
M2=round(worksheet.cell(10, 15).value)
INTER=round(worksheet.cell(10, 16).value)
INSTR=round(worksheet.cell(10, 9).value)
start_time = datetime.time(H2,M2,0,0)
first_tick_flag = True
def on_ticks(ws, ticks):
global first_tick_flag,start_time
if first_tick_flag:
first_tick_flag = False
start_time = time.time()
end_time = time.time()
if int(end_time - start_time) >=INTER:
start_time = end_time
for tick in ticks:
YB=tick['last_price']
rt1=datetime.datetime.now()
with open('10.txt', 'a') as file:
file.write(str(YB)+"\n")
file.write(str(rt1)+"\n")
def on_connect(ws,response):
ws.subscribe([INSTR])
ws.set_mode(ws.MODE_LTP, [INSTR])
def on_close(ws,code,reason):
ws.stop()
kws.on_ticks=on_ticks
kws.on_connect=on_connect
kws.on_close=on_close
kws.connect()
}
Tagged:
This discussion has been closed.