簡體   English   中英

如何在 Python 中循環以下代碼?

[英]How to loop the following code in Python?

我是 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      

不幸的是,它沒有奏效。 你對解決方案有什么想法嗎?

非常感謝!

您想將 Plant 交換為: order = process_flex(i) 因為 i 是 Plant 的一個元素

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

    return return_orders     

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM