如何在Python中循环以下代码?

问题描述 投票:0回答:1

我是Python的新手,但是我尝试创建以下交易策略,但是找不到找到针对不同产品(在这种情况下的交易时间)进行循环的方法。

def strategy(area_code, product, orders, environment):
    order = None
    new_orders = [] 
    Quantity = 5
    price_delta = 0.1

    def process_flex(Plant):

        order = None
        Tur1 = Plant + "1"

        if Tur1Volume > 0:
            if Tur1Price:
                order = None
                if check_if_we_have_order_on_the_market(Plant,Tur1)==0:
                    order =  package.create_sell_order(area_code, Tur1Volume, Quantity, calculate_selling_price(Tur1Price), price_delta, product, environment.current_datetime).with_label((Plant,Tur1))
                if order:
                    new_orders.append(order)
            else:
                order = None

        return 

    process_flex("bla")
    process_flex("blabla")
    process_flex("blablabla")


    return new_orders

此代码仅适用于一种产品(1小时),不适用于所有24种产品。我认为它可以像这样工作:

    for product in products:
        Plant = ['bla', 'blabla', 'blablabla']
        for i in Plant:
            order = process_flex(Plant)
        return_orders.append(order)

    return return_orders      

不幸的是,它没有用。您对解决方案有什么想法吗?

非常感谢!

python algorithmic-trading
1个回答
1
投票

您想将Plant交换为:顺序= process_flex(i)因为我是植物的元素

    for product in products:
        Plant = ['bla', 'blabla', 'blablabla']
        for i in Plant:
            order = process_flex(i)
        return_orders.append(order)

    return return_orders     
© www.soinside.com 2019 - 2024. All rights reserved.