gpt4 book ai didi

python - 类型错误 : unsupported operand type(s) for *: 'instancemethod' and 'int'

转载 作者:太空宇宙 更新时间:2023-11-03 18:40:43 24 4
gpt4 key购买 nike

我正在尝试调试一些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'])

最佳答案

似乎您忘记在函数调用后添加 (),所以:

self.exchange.account.get_fee() * 2

经过进一步研究,您的函数本身似乎有问题:

def get_fee(self):
return self.get_fee

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

关于python - 类型错误 : unsupported operand type(s) for *: 'instancemethod' and 'int' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20561567/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com