Order Place function not returning order ID

jenish_shakti
Hello,

I am checking few conditions in my individual options leg and once condition satisfied, it first squareoff that leg and then take new position. The condition checks every 3 seconds.

Sometimes kite api is not returning order ID in those three seconds and it results in multiple order placing.

In orderbook, orders are showing.(kite app).
But order_place not returning order_id.

This problems happening during high volatility and during expiry days.

Please advise exception code to follow in this case.

I would like to put logic in exception that it will check orderbook and fetch order_id that match current time hour and minute, with symbol name, buy/sell and qty.

Regards
Tagged:
  • rjamitsharma
    It always returns order ID

    But order fill may take some time


    If it happens please share your code
  • jenish_shakti
    Here is the code.

    Summary of the code:
    • This code verifies "AA" column of excel. And if any cell of "AA" column is TRUE then it execute code accordingly.
    • Also, It will place order_id in "AF" column. "AF" column should not be blank. If blank, "AA" remains "TRUE" until then.
    • Code execute every two seconds.
    • I have attached code, orderbook and print information herewith.
    Please advise.


    import schedule
    import xlwings as xw
    import kiteSettings
    from kiteconnect import KiteConnect
    import logging
    import time
    from datetime import datetime
    import Squareoff


    kite = KiteConnect(kiteSettings.api_key)
    kite.set_access_token(kiteSettings.access_token)
    wbtest = xw.Book("main.xlsm")


    def order_place1(symbol, bs, qty, price1):
    # Place an order
    if bs == "BUY":
    transaction_type1 = kite.TRANSACTION_TYPE_BUY,
    elif bs == "SELL":
    transaction_type1 = kite.TRANSACTION_TYPE_SELL,
    try:
    order_id = kite.place_order(
    variety=kite.VARIETY_REGULAR,
    exchange=kite.EXCHANGE_NFO,
    tradingsymbol=symbol,
    transaction_type=transaction_type1,
    quantity=qty,
    price=price1,
    product=kite.PRODUCT_NRML,
    order_type=kite.ORDER_TYPE_LIMIT
    )

    logging.info("Order placed. ID is: {}".format(order_id))
    except Exception as e:
    logging.info("Order placement failed: {}".format(e.message))

    return order_id



    def sch_chk():

    try:
    i = 51

    while i < 72:
    # B18 cell is permanent "TRUE". "AA" column is condition checking to enter into order.
    if wbtest.sheets("BANKNIFTY").range("AA" + str(i)).value == wbtest.sheets("BANKNIFTY").range("B18").value:
    BS1 = wbtest.sheets("BANKNIFTY").range("AA" + str(i)).offset(0, 1).value
    sym1 = wbtest.sheets("BANKNIFTY").range("AA" + str(i)).offset(0, 11).value
    prc1 = wbtest.sheets("BANKNIFTY").range("AA" + str(i)).offset(0, 4).value
    qty1 = 300

    a4 = order_place1(sym1, BS1, int(qty1), prc1)
    wbtest.sheets("BANKNIFTY").range("AA" + str(i)).offset(0, 5).value = a4
    print("Order BankNifty PE")
    i = i + 1

    #print("Short PE Cycle Completed")


    print(datetime.now())

    except:
    #logging.info("Excel Loop Order Scan has some error: {}".format(e.message))
    pass


    if __name__ == '__main__':
    while True:
    try:
    sch_chk()
    time.sleep(2)
    except:
    pass





  • jenish_shakti
    Code is not looking properly, If possible follow below link to refer code:
    https://codeshare.io/N3Z098

    Normally this problem is happening during high volatility Wednesday/Thursday.
  • boobeshwari
    use return order_id['order_id']
Sign In or Register to comment.