2013-12-13 137 views
0

我試圖調試一些Python(接近零語言知識)。在一些代碼,有一行:TypeError:不支持的操作數類型爲*:'instancemethod'和'int'

self.min_spread = self.exchange.account.get_fee * 2 

這將返回錯誤:

Traceback (most recent call last): 
    File "launch.py", line 33, in <module> 
    main() 
    File "launch.py", line 28, in main 
    bot = marketmaker.MarketMaker(exchange, pair) 
    File "T:\mm-1.01\src\strategies\marketmaker.py", line 22, in __init__ 
    self.min_spread = self.exchange.account.get_fee * 2 
TypeError: unsupported operand type(s) for *: 'instancemethod' and 'int' 

經過一番研究,我加get_fee之後的括號,但這並沒有影響。哪裏不對?

這是Python 2.7。

編輯:

只是爲了澄清,如果我加括號,誤差變:

File "T:\mm-1.01\src\strategies\marketmaker.py", line 22, in __init__ 
    self.min_spread = self.exchange.account.get_fee() * 2 
TypeError: unsupported operand type(s) for *: 'instancemethod' and 'int' 

編輯:

下面是賬戶類:

class Account(): 


    def __init__(self, agent): 
     self.agent = agent 
     self._account() 

    def _account(self): 
     pass 

    def get_balance(self): 
     self._update_balance() 
     return self.balance 

    def get_fee(self): 
     return self.get_fee 

    def get_open_orders(self): 
     self._update_open_orders() 
     return self.open_orders 

    def cancel(self, order_id): 
     pass 

    def cancel_all(self, order_type='all'): 
     if order_type == 'all': 
      for order in self.get_open_orders(): 
       self.cancel(order['order_id']) 
     else: 
      for order in self.get_open_orders(): 
       if order['type'] == order_type: 
        self.cancel(order['order_id']) 
+0

'self.exchange.account.get_fee()'不需要任何輸入嗎? – Kraay89

+1

發佈您的整個班級。否則很難說,因爲你的功能可能需要參數。 –

+0

我不這麼認爲,雖然我不在這裏,因爲我不會說Python。該方法對我沒有意義(C#dev),它被定義爲def get_fee(self): return self.get_fee – RBT

回答

0

它好像你忘了在函數調用後添加(),所以:

self.exchange.account.get_fee() * 2 

經過進一步研究,似乎你的函數本身有一個問題:

def get_fee(self): 
    return self.get_fee 

現在返回self.get_fee這是一個實例方法,它不返回任何值。這就是你遇到錯誤的原因。

+0

有點奇怪,但他說他已經試過..... –

+0

@KDawG然後這需要更多的研究。我們需要看全班。 –

+0

#遊戲確切.... –

相關問題