Below is my simple code to create candles and it was working fine for last 2 weeks. Today suddenly it is not able to connect apparently due which i am not able to receive any tickers.
import logging,pickle,sys,time from Config import * from kiteconnect import KiteTicker from datetime import datetime
# print "Hi" def on_ticks(ws, ticks): # Callback to receive ticks. # logging.debug("Ticks: {}".format(ticks)) global initial_time_1, initial_time_3 for tick in ticks: # print tick['instrument_token'] print tick #Dump vol_dict data every minute if tick['instrument_token'] in vol_dict: vol_dict[tick['instrument_token']]['CMP'] = float(tick['last_price']) if float(tick['ohlc']['high']) > float(vol_dict[tick['instrument_token']]['high']) : vol_dict[tick['instrument_token']]['high'] = float(tick['ohlc']['high']) if float(tick['ohlc']['low']) < float(vol_dict[tick['instrument_token']]['low']) : vol_dict[tick['instrument_token']]['low'] = float(tick['ohlc']['low']) # vol_dict[tick['instrument_token']]['high'] = tick['ohlc']['high'] # vol_dict[tick['instrument_token']]['low'] = tick['ohlc']['low'] vol_dict[tick['instrument_token']]['X'] = float(tick['last_price'])*float(tick['volume'])/100000 else: data = {} data['X'] = float(tick['last_price'])*float(tick['volume'])/100000 data['CMP'] = float(tick['last_price']) data['open'] = float(tick['ohlc']['open']) data['close'] = float(tick['ohlc']['close']) data['high'] = float(tick['ohlc']['high']) data['low'] = float(tick['ohlc']['low']) data['change'] = round(float(tick['change']),2) vol_dict[tick['instrument_token']] = data
time_diff = round((datetime.now()-initial_time_1).total_seconds()) if time_diff > 19: initial_time_1 = datetime.now() with open('ohlc.pickle', 'wb') as handle: pickle.dump(vol_dict, handle, protocol=pickle.HIGHEST_PROTOCOL)
# time_diff = round((datetime.now()-initial_time_3).total_seconds()) # if time_diff > 179: # initial_time_3 = datetime.now() # with open('3ohlc.pickle', 'wb') as handle: # pickle.dump(vol_dict, handle, protocol=pickle.HIGHEST_PROTOCOL)
def on_connect(ws, response): # Callback on successful connect. # Subscribe to a list of instrument_tokens (RELIANCE and ACC here). print "connected" # print ws.is_connected() ws.subscribe(ilist)
# Set RELIANCE to tick in `full` mode. # ws.set_mode(ws.MODE_FULL, [738561])
# Assign the callbacks. kws.on_ticks = on_ticks kws.on_connect = on_connect
# Infinite loop on the main thread. Nothing after this will run. # You have to use the pre-defined callbacks to manage subscriptions. print "connecting" kws.connect()
PS: Please don't post account or session specific tokens on a public thread.
ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))