簡體   English   中英

高速公路| Python:提供SubscriptionOptions時,訂閱不再觸發處理程序

[英]Autobahn | Python: Subscription no longer triggering handler when SubscriptionOptions are provided

我目前正在用Python構建一個加密貨幣交易平台,並使用高速公路來接收市場事件。 我在使用訂閱選項時遇到問題。

當我僅使用(處理程序,主題)參數創建預訂,並使處理程序采用單個參數時,一切正常。 但是,當我使用(處理程序,主題,選項)參數創建預訂,並使處理程序帶有兩個參數時,不會調用處理程序。 在文檔中,它指出在這種情況下,處理程序應具有三個參數args,kwargs和details。 當我使處理程序接受三個參數時,它也不起作用。 我無奈地嘗試了0到5個參數之間的所有內容。

簡而言之,當我不使用任何訂閱選項並為處理程序提供一個參數時,它可以正常工作。 使用訂閱選項時, 無論使用多少參數 ,都不會觸發處理程序。

我嘗試打印出該對,並且它是有效的字符串,並且嘗試打印出這些選項,並且它是有效的subscriptionsoptions對象。 注意,我將“ none”用作匹配條件。 我仍然收到訂閱確認,沒有錯誤。

任何建議將不勝感激。

代碼如下。

def onJoin(self, details):
    print("{} client session ready".format(self.exchange))

    def marketEvent(args, kwargs, details):
        print("marketEvent called")

    # Read in configuration files
    try:
        pairs = [line.strip() for line in open("conf/" + self.exchange + ".conf")]
    except:
        print("Configuration file not found for {}!".format(self.exchange))
        sys.exit(1)

    # Subscribe to each currency pair / topic in the conf file
    for pair in pairs:
        try:
            # provide currency pair name to handler 
            options = SubscribeOptions(details_arg = pair)
            yield from self.subscribe(marketEvent, pair, options)
            print("subscribed to {} on {}".format(pair, self.exchange))
        except Exception as e:
            print("could not subscribe to {} on {}: {}".format(pair, exchange, e))
            sys.exit(1)

已修復,在我的一個朋友的幫助下。 marketEvent所需的簽名如下:

marketEvent(事件,**詳細信息)

暫無
暫無

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

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