Python code for order status

Ashok121
My order no. is 180408000002439

Can you please let me know how to check status of above order?
If python code is given, it will be great help.

thanks in advance.
Tagged:
  • zartimus
    @Ashok121 Did you try the above the code on your console?
    1. requests does not have :meth response
    2. Headers cannot be send as url params
    3. URL is still wrong
    Please check into pykiteconnect lib
  • Ashok121
    Sir,
    I am not much expert in coding and reading/interpreting documentation.

    Can you please give me single line python code for checking order status when order_id is known.
    For example my order_id is 180408000002439.

    It will be great help if you provide above. I am struggling solution for this issue for long time.
  • Ashok121
    Ashok121 edited April 2018
    response=requests.get("https://api.kite.trade/orders/180409001794998?v=3&api_key=XXX:access_token=XXX")

    With above, I am getting following error: Response[403]
  • zartimus
    @Ashok121 That puts me into asking how did you get the access token in the first place?
    https://github.com/zerodhatech/pykiteconnect is the easiest way to interact with kiteconnect APIs on python. Please check into the installation section and documentation for the same.

    With bare python requests,
    import requests
    requests.get(
    "https://api.kite.trade/orders/180409001794998",
    headers={
    "X-Kite-Version": "3",
    "Authorization": "token {api_key}:{access_token}".format(
    api_key="<YOUR-API-KEY>",
    access_token="<YOUR-ACCESS-TOKEN>"
    )
    }
    )
  • Parva
    @sujith Is there any way to retrieve status of a specific order using order_id?
  • rakeshr
    @Parva
    Yeah, you need to pass order_id as param to retrieve complete order history.Check the documentation here.
  • Parva
    @rakeshr Thank you for your response.

    What I mean to ask is, let's say I have 100 orders in my order book and I want to check the status of only a single order using order_id.

    kite.orders() : this will give me the complete order book
    kite.orders()[0] : this will give me the 1st order
    kite.orders()[0]['status'] : this will give me the status of 1st order

    But what if I don't know the number of my order but just my order_id. Do I need to search all the orders I have placed so far for the day or is there any way by which I can get the status of that specific order directly?
  • Imran
    hii @Parva

    if you want to search by only order id
    try using this
    received=kite.orders()
    for individual_order in received:
    if int(individual_order['order_id'])==181020000008348:
    print(individual_order['status'])
  • Parva
    hey @Imran

    Thankyou for your response. Do you think this will affect the time of execution for the code which handles the buy and sell operations? (considering that it will have to search for this order_id from more than 100 or 200 orders)
  • Imran
    It won't slow execution time by much.
    Once the data has been received it doesn't take much time to parse
  • rakeshr
    @Parva
    Use kite.order_history(order_id='XXXXXX'), to retrive order history of specific order using only order_Id.
  • Parva
    @Imran @rakeshr Thankyou guys for your help
  • Parva
    @Imran @rakeshr

    My algo keeps on disconnecting and reconnecting to the kiteconnect servers. I am using 5 if conditions which check the status of different orders using this functions:

    def get_status(oid):
    status = kite.order_history(order_id=oid)[(len(kite.order_history(order_id=oid)))-1]['status']
    return status


    Is it possible that because of sending so many requests to receive order history, I might be getting disconnected and reconnected every alternate second?
  • rakeshr
    @Parva
    Make sure you are not exceeding below rate limits.
    Quote API - 1r/s
    Order place API - 5r/s
    Historical API - 3r/s
    All other endpoints - 10r/s
  • Parva
    @rakeshr Thank you. I will take care of this. Just to be sure, the order history request falls under Quote API, right?

    Also, is it possible to use multi threading with Kite Connect? As in, I would like to make a script in which one thread takes care of the order status' while the other does buy and sell operations. If yes, can you please point me to a guide/tutorial that can help me do so?

    Thank you
  • sujith
    Hi @Parva,
    In simple words, Kite Connect is just a library which makes HTTP API calls. Once you have access token you can make an API call from any thread. There is no restriction at the library level. You can just spin off a new thread and make API call.
Sign In or Register to comment.