Home > front end >  how to use 2 loops in 1 for loop
how to use 2 loops in 1 for loop

Time:09-12

So I have a for loop that is placing orders for me on an exchange. The loop currently loops through a list of prices and places 1x order at each price. I also have a list of order sizes I would like to loop through but cant figure out how. I'm new to python so sure its an easy fix but currently very much stuck.

I want to loop the size list though where qty=0.01 is in the current for loop

#Order Sizing.

size_1 = 0.01
size_2 = size_1*1.25
size_3 = size_2*1.25
size_4 = size_3*1.25
size_5 = size_4*1.25
size_6 = size_5*1.25
size_7 = size_6*1.25
size_8 = size_7*1.25

order_size_list = [size_1, size_2, size_3, size_4, 
size_5, size_6, size_7, size_8]


# Place Orders.

for bid_price_loop in bid_price_list:
    session_perp.place_active_order(
        symbol="ETHUSDT",
        side="Buy",
        order_type="Limit",
        qty=0.01,  <-----------"second list loop here"
        price=bid_price_loop,
        time_in_force="PostOnly",
        reduce_only=False,
        close_on_trigger=False)

Thanks in advance for any help, its very much appreciated.

CodePudding user response:

you zip 2 list

something like this

a = list(i for i in range(10))
b = list(j for j in range(112))
for x, y in zip(a, b):
    print(x, y)
  • Related