Python Client: "kws.connect()" is not triggering the infinite loop, plesae help

renjitharajan84
I have a small learning program to print the tick data of one stock. It runs perfectly fine and prints the LTP, but curser stops after printing one LTP, seems like the "kws.connect()" is not triggering the infinite loop.

it could be some other reasons as well, please some experts in this forum check this and tell me what is missing in this simple code

#######################################
from kiteconnect import KiteConnect
from kiteconnect import KiteTicker

#-------------------------login------------------------------------#

api_k = "xxxxx" # api_key
api_s = "yyyyy" # api_secret
access_token = "zzzzz"

def get_login(api_k, api_s): # log in to zerodha API panel
global kws, kite
kite = KiteConnect(api_key=api_k)

kite.set_access_token(access_token)
kws = KiteTicker(api_k, access_token)

get_login(api_k, api_s)

#-------------------------login------------------------------------#

def on_ticks(ws, ticks):
print(ticks)

def on_connect(ws, response):
ws.subscribe([177665])
ws.set_mode(ws.MODE_LTP, [177665])

kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect()

##################################

terminal screenshot:


program freezes execution after printing one line. please help me what is wrong with this code.

thanks,
ACR
1.png 13.5K
  • renjitharajan84
    Hello forum experts, it is a humble request, this might look simple to you however, please help me if you know the solution, i am really stuck here in my learning process. thanks in advance.
    ACR
  • rakeshr
    @renjitharajan84
    We believe you are running this in non-market hours. In non-market hours, you will receive only the last tick.
  • renjitharajan84
    thanks @rakeshr I will check in the market hours and update the status.
  • renjitharajan84
    @rakeshr Really appreciate your willingness to help beginners, thank you so much for your guidance. it worked like a charm in the market hours! :)
Sign In or Register to comment.