How to pull specific orders depending on order status value?

mlearner
mlearner edited July 2020 in Python client
Is there a method exposed for pulling list of orders depending on order status value?

Say if I have more than 100 orders placed/executed/open on a day and I only want to retrieve orders that are currently in "OPEN" status.

The only way I can do currently is pull all orders and then iterate over JSON value to segregate only "OPEN" orders. Code becomes too verbose and may also lead to latency in my app's execution because of increase in computation.

c = kite.orders
json_data = json.dumps(c, default=json_util.default)
order_dump = json.loads(json_data)
Tagged:
  • sujith
    We don't have a separate endpoint to fetch pending orders. You can fetch the order book and filter out the pending orders with just one line. Just look for orders with a status other than CANCELLED, REJECTED, or COMPLETE.
  • mlearner
    Since we have to also serialize the JSON and then iterate over serialized object, I am not sure if there is a efficient way to do it. I am doing it like below at present. This is a working code that pulls all "OPEN" orders -

    c = kite.orders()
    json_data = json.dumps(c, default=json_util.default)
    order_list = json.loads(json_data)

    for order in order_list:
    if(order['status']=='OPEN'):
    print(order['order_id'])

    Can you please suggest improvements here? I find this too verbose.
  • rakeshr
    @mlearner
    Since we have to also serialize the JSON and then iterate over serialized object,
    If you are using kiteconect python package, you don't have to serialize JSON. Response from kite.orders() is list of python dictionary, you can directly iterate it to check for condition.
    if(order['status']=='OPEN')
    Instead, you can try doing status != COMPLETE CANCELLED or REJECTED
Sign In or Register to comment.