Kite Ticker not coming

shashanksonie
shashanksonie edited September 2018 in Python client
Hi ,

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


initial_time_1 = datetime.now()
initial_time_3 = datetime.now()

# logging.basicConfig(level=logging.DEBUG)
access_token = "XXXXXXXX"
# Initialise
kws = KiteTicker(api_key, access_token,reconnect=True)
ilist = [5633, 6401, 2079745, 25601, 325121, 40193, 41729, 49409, 54273, 60417, 70401, 1510401, 4267265, 81153, 85761, 1195009, 94977, 101121, 103425, 108033, 2714625, 2911489, 134657, 140033, 2029825, 2763265, 149249, 3903745, 3905025, 160001, 160769, 194561, 177665, 5215745, 1215745, 486657, 197633, 5444865, 3513601, 215553, 2800641, 3771393, 225537, 232961, 245249, 173057, 261889, 1207553, 1895937, 3039233, 315393, 2513665, 1850625, 340481, 341249, 345089, 2747905, 348929, 359937, 356865, 7712001, 1270529, 4774913, 3677697, 2883073, 387841, 3663105, 2865921, 1346049, 7458561, 408065, 415745, 3920129, 424961, 2997505, 1723649, 2661633, 3001089, 4632577, 7670273, 492033, 1790465, 2061825, 6386689, 511233, 2939649, 2672641, 519937, 3400961, 1041153, 2815745, 2674433, 7982337, 548353, 4488705, 3675137, 1076225, 6054401, 1629185, 8042241, 593665, 2955009, 633601, 636673, 7455745, 617473, 2905857, 3660545, 681985, 2730497, 2906881, 731905, 4708097, 3930881, 737793, 738561, 141569, 7577089, 758529, 779521, 806401, 837889, 1102337, 1887745, 857857, 3431425, 1837825, 873217, 878593, 884737, 4343041, 895745, 2953217, 3465729, 897537, 900609, 3529217, 2170625, 4278529, 4369665, 2952193, 2752769, 2889473, 784129, 3932673, 951809, 969473, 1921537, 3050241, 975873]
vol_dict = {}


# 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()

# kws.resubscribe()
  • sujith
    Can you paste the logs here?

    PS: Please don't post account or session specific tokens on a public thread.
  • shashanksonie
    It says -

    ERROR:kiteconnect.ticker:Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (403 - Forbidden))
Sign In or Register to comment.