PYTHON: not getting ticks with kite3.0 KiteTicker

MAG
MAG edited February 2018 in Market data (WebSockets)
I am migrating my code over to kiteconnect 3.0 and I am stuck with the websocket library receiving ticks.
The following is excerpt from working code for kiteconnect 2.0 that was modified for kiteconnect 3.0 as per the documentation.

Can you please help me find out whats wrong? The connection seems to instantiate fine. But Its not getting any ticks
When I run the code, it calls the on_connect method successfully but then nothing seems to happen. No ticks. Just to confirm I added a bunch of instrument tokens and not just one. The logic is between these instrument tokens there would definitely be one tick generated per second.
#!/usr/bin/python3
from kiteconnect import KiteTicker # Kiteconect library = INSTALLED: 3.7.0b5
import logging
import pprint
import datetime
import sys
import time

logging.basicConfig(level=logging.DEBUG)

def on_tick( tick , kws ) :
print(tick)
#def on_tick ends

def on_connect( kws , response) :
print("Onconnect called")
subscriptioncompleted = 0
subscount=0
subscriptionlist = [1723649, 12932866, 12856834, 12902146, 13054978, 12889858, 13176066, 4583169, 12161282, 12984322, 4716033, 12941058, 12199938, 13046018, 12844034, 12879106, 6422529, 12899586, 1158401, 12199682, 12209666, 12195586, 109057, 12878850, 13184258, 325121, 12158978, 12861954, 3894785, 12845058, 13000194, 25601, 7685889, 5256193, 5533185, 13003266, 12868098, 13168130, 12234754, 207617, 3774721, 13076226, 12871170, 4933377, 126721, 12250626, 12903938, 12887554, 12875266, 12206850, 12230658, 2974209, 12205314, 12160514, 12237826, 13171970, 3369473, 3020289, 12224514, 12219138, 5097729, 12985858, 12867586, 12886786, 12203522, 12904194, 3402241, 2009089, 4341505, 12933378, 143105, 12857602, 2907905, 37889, 12940802, 2931713, 13177858, 5440513, 558337, 12239106, 12880898, 5460993, 13176834, 12225026, 2081793, 2029825, 12943106, 13188354, 4423425, 12284418, 12940546, 3811585, 12883458, 12987650, 12900610, 12856066, 2873857, 3903745, 5479937, 12849922, 12983810, 4931841, 12176898, 5444865, 2199297, 12160258, 12210946, 4474113, 5691649, 12193538, 12240386, 189953, 13187842, 12995842, 3712257, 13063682, 193793, 13155586, 12984834, 3645441, 12159746, 5436929, 12893442, 2928385, 2986753, 13020930, 107265, 13067266, 12877826, 197633, 12176642, 12870658, 12949250, 73473, 12907010, 12200194, 12929282, 1906177, 12201730, 13166594, 5318657, 12858114, 4264193, 4617985, 12947714, 595969, 12222466, 12214274, 12880386, 12169730, 13061122, 7971329, 12978434, 34817, 12193282, 12941570, 12194818, 113921, 12212994, 12890626, 12949762, 2800641, 131329, 12977154, 13014530, 12890114, 12880642, 5552641, 12865794, 13064962, 2885377, 12962562, 1459457, 12876802, 12197378, 12897026, 12849154, 12845314, 12208642, 12930050, 3513601, 12911874, 5227265, 3792129, 1376769, 97281, 219393, 12869890, 12932610, 12897794, 12859906, 13065474, 12195330, 5420545, 12856578, 3077633, 13126914, 12943362, 12216834, 12236290, 12884226, 12939010, 4718337, 4481793, 3794689, 12877058, 425729, 12865282, 12210178, 1634561, 12850946, 3721473, 13074946, 1148673, 12175362, 12945410, 12201986, 1456129, 12858370, 12877314, 4421121, 12897282, 1147137, 12236546, 12988418, 13017090, 12943618, 12233474, 12244994, 12241922, 152321, 3685889, 2753281, 221697, 12868354, 12204546, 12883202, 5591041, 13178114, 3500289, 4898049, 12940290, 12896514, 13071874, 999937, 3558401, 12213762, 12994306, 215553, 12871426, 13184002, 12848130, 12159490, 12279554, 12161026, 13119746, 8004353, 12221186, 13187586, 88833, 13002498, 13002754, 2079745, 12870146, 3784449, 13043202, 1471489, 4513793, 3812865, 12204034, 6404353, 13042434, 5404929, 5105409, 2722305, 12854530, 12167682, 879361, 5556225, 6483969, 12996098, 12226562, 13004290, 39425, 12241154, 13172994, 12242946, 3729153, 12203010, 94209, 164097, 12888834, 7707649, 5459201, 12174338, 2911489, 3553281, 12933122, 13148418, 1187329, 13055234, 12931330, 12224002, 12256514, 12847874, 12238850, 13057538, 12843522, 4404481, 3858689, 5160961, 4565249, 4376065, 163073]

#ASHOKLEY18APRFUT 12932866
print( subscriptionlist )
print( 'subscriptionlist element is ', type( subscriptionlist[ 0 ] ) ) #to confirm subscriptionlist items are int
kws.subscribe( subscriptionlist )
#def on_connect ends

def mainfunc():
global ERRORCOND
global lasttickrecd
lasttickrecd = ''
ERRORCOND=0
print('main called')

kws = KiteTicker( API_KEY , ACCESS_TOKEN ) #API_KEY & ACCESS_TOKEN are variables containing the values.
print('KWS login completed')


kws.on_tick = on_tick
kws.on_connect = on_connect

print('calling KWS.connect')
response = kws.connect( threaded=True, disable_ssl_verification=True, proxy=None)
print('KWS.connect done')

while [ 1 ] :
pass
##some housekeeping will be done here to check time and disconnect/reconnect at market open / close, monitor for errors etc.
#def mainfunc ends
ret=mainfunc()
  • Vivek
    Seems like your `on_tick` callback is wrong. It takes `ws` WebSocket object as first param and `ticks` as second param. Check example for reference - https://github.com/zerodhatech/pykiteconnect#websocket-usage
  • MAG
    Ignore this for the moment. I think I have got this sorted.
  • MAG
    This has been resolved. Minor issues and RTFM multiple times helped solved the issue.
    It was
    kws.on_ticks = on_ticks # in kiteconnect 3.0
    instead of
    kws.on_tick = on_tick # in kiteconnect2.0
  • MAG
    @vivek What does this error mean
    on_close(): ERROR : 1006, connection was closed uncleanly (I dropped the WebSocket TCP connection: not enough arguments for format string)
  • Vivek
    Seems like you are trying to format a string in your callback without any argument. So basically if your logic is wrong in callbacks it will be raised like this.
Sign In or Register to comment.