我試圖調試一些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'])
'self.exchange.account.get_fee()'不需要任何輸入嗎? – Kraay89
發佈您的整個班級。否則很難說,因爲你的功能可能需要參數。 –
我不這麼認爲,雖然我不在這裏,因爲我不會說Python。該方法對我沒有意義(C#dev),它被定義爲def get_fee(self): return self.get_fee – RBT