How to cancel all open and pending orders in Aliceblue

This function is developed over AliceBlue Official Python library.

#Request
def cancel_all_orders():
  orders = alice.get_order_history()
  for order in orders:
    if(order["Status"]=="pending" or order["Status"]=="after market order req received"):
      print(alice.cancel_order(order_id = order["Nstordno"]))

cancel_all_orders()
#Cancelling all Orders. 

I Developed this function at midnight. Worked fine with AMO Orders. Did not tested in Market time. Will do. If you spot an error, Please do tell.

In the previous API, the pending, canceled, and executed orders were divided. In this API, We need to create that division ourselves.

Thanks a lot for the snippet. It really helps.
Status should be “open” instead “pending”

1 Like

Thanks I have not tested in market time.

#Request
def cancel_all_orders():
  orders = alice.get_order_history()
  for order in orders:
    if(order["Status"]=="open" or order["Status"]=="after market order req received"):
      print(alice.cancel_order(order_id = order["Nstordno"]))

cancel_all_orders()
#Cancelling all Orders.

I have fixed as per your suggestion :slight_smile:

Check this correct version.

def cancel_all_orders():
  orders = FV.alice.get_order_history('')
  for order in orders:
    if(order["Status"]=="open" or order["Status"]=="trigger pending" or order["Status"]=="after market order req received"):
      FV.alice.cancel_order(order["Nstordno"])



1 Like

You added trigger_pending

Thanks, man. I will let you know once I push the custom library.

Hi, Please share me the link to custom library. where is it :slight_smile:

Waiting to see how they deal with 2FA issue. TOTP or OTP or what