how do i differentiate between Limit and Market orders.

vipin0761
I am running the below code and all order updates are flowing in as LIMIT price instruction in on_order_update() and tried modifying a limit order to market and also sending a new market order from kite but it just shows both as limit order type.



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()
  • sujith
    You need to use order_update as the event for fetching orderbook and checking the latest status and other fields.
    They are asynchronous messages pushed by OMS and we just relay and they are out of orders in some cases.
Sign In or Register to comment.