on_order_update not working over websocket

vipin0761
all other functions are getting triggered but the order updates are not flowing in. no errors. please can someone advise what could be the possible issue.

import mysql.connector
import time
import logging
import KiteConnect
from KiteConnect import KiteTicker
from home import *

# Callback for tick reception.
def on_ticks(ws, ticks):
if len(ticks) > 0:
logging.info("Current mode: {}".format(ticks[0]["mode"]))


# Callback for successful connection.
def on_connect(ws, response):
logging.info("Successfully connected. Response: {}".format(response))
# RELIANCE BSE
tokens = [738561]
ws.subscribe(tokens)
ws.set_mode(ws.MODE_LTP, tokens)
logging.info("Subscribe to tokens in Full mode: {}".format(tokens))
logging.debug('test tsest.,mv?LDfeqalfgl')


# Callback when current connection is closed.
def on_close(ws, code, reason):
logging.info("Connection closed: {code} - {reason}".format(code=code, reason=reason))


# Callback when connection closed with error.
def on_error(ws, code, reason):
logging.info("Connection error: {code} - {reason}".format(code=code, reason=reason))


# Callback when reconnect is on progress
def on_reconnect(ws, attempts_count):
logging.info("Reconnecting: {}".format(attempts_count))


# Callback when all reconnect failed (exhausted max retries)
def on_noreconnect(ws):
logging.info("Reconnect failed.")

def on_order_update(ws, data):
logging.debug(data)


def listener():
try:


mydb = DBSession()
mydb.Connect()
secondary = mydb.get_all_active_secondary_users()
primary_user = ZerodhaUser(secondary[0])
kws = KiteTicker(primary_user.get_api_key(), primary_user.get_access_token())

# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_close = on_close
kws.on_error = on_error
kws.on_connect = on_connect
kws.on_reconnect = on_reconnect
kws.on_noreconnect = on_noreconnect
kws.on_order_update = on_order_update
#kite = KiteConnect(api_key=primary_user.get_api_key())
#kite.set_access_token(access_token=primary_user.get_access_token())
#flag = kite.orders()
#print(flag)

# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect(threaded=True)

while True:
if kws.is_connected():
logging.info('Session is active')
time.sleep(5)


except Exception as e:
print(e)



master_listener()
  • rakeshr
    I just skimmed through your code, it looks fine. It should be fine if you are calling the listener() method properly. Are you able to see, such placed orders on the kite web order book? Are those orders successfully placed?
  • vipin0761
    yes although I tried AMO order's. but, that should not make any difference i guess.
  • vipin0761
    it should listen to order's placed from kite gui as well right?
  • sujith
    @vipin0761,
    Order updates are not sent for AMO, you can try a regular order.

    Yes, you will receive order updates for orders place on Kite Web as well on Websocket API.
Sign In or Register to comment.