jeudi 30 avril 2020

if condition not met but still prints "if" in nested if statements with for loop

Why does this code never goes in to "else" and print accordingly when the condition in "if" is not satisfied?

j=0
for i in data:
  if j<10:

    if i['product']['id'] == p_id:
        if (i['stop_price']!='None'):
            print("Order Type:" +  str(i['stop_order_type']))
            print("Stop Price: " + str(i['stop_price']))

        else:
            print("Order Type: " + str(i['order_type']))



        print("Limit Price: " + str(i['limit_price']))
        print("Side: " + str(i['side']))
        print("Size: " + str(i['size']))
        print("Unfilled Size: " + str(i['unfilled_size']))

        print("\n\n")

    j+=1

It prints the below output:

Order Type:stop_loss_order
Stop Price: 405.0
Limit Price: 400.0
Side: buy
Size: 1
Unfilled Size: 1



Order Type:None
Stop Price: None
Limit Price: 280.0
Side: sell
Size: 1
Unfilled Size: 0



Order Type:None
Stop Price: None
Limit Price: 300.0
Side: sell
Size: 1
Unfilled Size: 1

But the correct Output should be:

Order Type:stop_loss_order
Stop Price: 405.0
Limit Price: 400.0
Side: buy
Size: 1
Unfilled Size: 1



Order Type:Limit
Limit Price: 280.0
Side: sell
Size: 1
Unfilled Size: 0



Order Type:Limit
Limit Price: 300.0
Side: sell
Size: 1
Unfilled Size: 1

Aucun commentaire:

Enregistrer un commentaire