TypeError:*支持的操作数类型*:'instancemethod'和'int'

时间:2013-12-13 07:50:19

标签: python

我正在尝试调试一些Python(接下来只有零语言知识)。在某些代码中,有一行:

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'])

1 个答案:

答案 0 :(得分:1)

好像你忘了在函数调用后添加(),所以:

self.exchange.account.get_fee() * 2

经过一些进一步的研究后,您的功能本身似乎存在问题:

def get_fee(self):
    return self.get_fee

现在它返回self.get_fee这是一个实例方法,它不返回任何值。这就是你收到错误的原因。