mercredi 24 novembre 2021

How to execute my if loop only once in python?

I'm using a if-loop to place an order to my console , but after condition is met it's getting printed several times.

if len(pos_df.columns) == 0 and len(ord_df.columns) == 0:
   for i in range(0,len(bricks_counts)):
       if bricks_counts[i] == -23 and red_neg == True:
           placeCoverOrder(ticker,"sell",quantity,high_down)
           print("sell order placed {}".format(ticker))
           break

I want this loop to be executed only once , means it should run only once in the first iteration and it shouldn't run in the second iteration(the if-loop shoould become false in the second iteration).

Any help would be very much helpful for me and must be appreciated. :)

Aucun commentaire:

Enregistrer un commentaire