我正在使用 Python 3.1、Spyder 5.4.2 和 IB API 10.19
`
class TradingApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self,self)
def error(self, reqId, errorCode, errorString, advancedOrderRejectJson):
print("Error {} {} {}".format(reqId,errorCode,errorString))
def contractDetails(self, reqId, contractDetails):
print("redID: {}, contract:{}".format(reqId,contractDetails))
def websocket_con():
app.run()
event.wait()
if event.is_set():
app.close()
我可以在 IDE 中成功运行一次,第二次失败并出现上述错误。如果我关闭 IPython 控制台,我可以再次运行它,如果失败则再次运行。如果我打开终端并导航到目录并运行它根本不会运行并且因上述错误而失败
我试过用类似的结果注释掉错误函数。它仅在关闭 IPython 控制台选项卡后运行,并且根本不在控制台中运行,给出
AttributeError: 'TradingApp' object has no attribute 'close'
在 websocket 函数下注释掉 if 语句做类似的事情,但给出错误 -1 504 未连接,在控制台中也是如此。