kite_connect.place_order() method returning None even after placing the order (rare case)

amanchaure14
amanchaure14 edited September 9 in Python client
sometimes, the place_order method of the kite_connect API returns None even after placing an actual order. Here is how I deal with this situation.
In my order execution block, I generate a unique tag string for each order that has to be sent, then just after the API call, I check if the the order is not None.
If it is None, then I would call the kite_connect.orders() API call, and extract the order_id with respect to the unique tag value that I used previously to place the order.
# python code
from kiteconnect import KiteConnect
kite_connect = KiteConnect(api_key="your_api_key")
kite_connect.set_access_token(access_token="your_access_token")

# create a unique tag for each order that you send to the broker via API
tag = "xyz_123"

order_id = kite_connect.place_order(
variety=kite_connect.VARIETY_REGULAR,
exchange='MCX',
tradingsymbol="CRUDEOIL24SEPFUT",
transaction_type='BUY',
quantity=1,
product='NRML',
order_type=kite_connect.ORDER_TYPE_LIMIT,
price=5600,
tag=tag
)

if not order_id:
order_id_list = [i for i in kite_connect.orders() if i['tag']==tag]
if len(order_id_list)>0:
order_id = order_id_list[0]['order_id']

# if the order_id is still None and there is no error produced in your place_order API call, you must check the broker terminal immediately to see if any order is placed.
Tagged:
  • amanchaure14
    the indentation got a little messed up after posting the code here, there are tab spaces after each if clause near the end of the code.
  • sujith
    Can you share the debug logs when it happens? You can enable debug flag while initializing pykiteconnect.
    Make sure to remove app and client specific tokens while sharing logs here.
Sign In or Register to comment.