on_order_update is not working

sathvisiva
I was expecting to get order info in websocket on_order_update function but i'm not getting any value, on_ticks() works perfectly.. Any leads what I'm missing

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


# Callback for successful connection.
def on_connect(ws, response):
logging.info("Successfully connected. Response: {}".format(response))
ws.subscribe(tokens)
ws.set_mode(ws.MODE_FULL, tokens)
logging.info("Subscribe to tokens in Full mode: {}".format(tokens))


# 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):
print("@" * 200)
print(data)

logging.info('Ticker: order update %s', data)


# 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_order_update = on_order_update
kws.connect(threaded=True)



count = 0
while True:
count += 1
if count % 2 == 0:
if kws.is_connected():
print("#" * 200)
print("placing order")
orderId = kite.place_order(variety=kite.VARIETY_REGULAR,exchange=kite.EXCHANGE_NFO,
tradingsymbol='BANKNIFTY21AUG35000PE',transaction_type=kite.TRANSACTION_TYPE_BUY,
quantity=1,price=21,trigger_price=60,product=kite.PRODUCT_NRML,
order_type=kite.ORDER_TYPE_LIMIT)
print("order placed")
print(orderId)
print("#" * 200)


sleep(50)
Tagged:
  • sujith
    1. Order updates are only sent when there is an update on the order, like partial fill, order modified. You won't receive order update when an order is just placed.
    2. Don't block the main thread that has Websocket connection. If you make the thread sleep then it will get disconnected.
Sign In or Register to comment.