尝试运行以下代码连接IB API
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
app = IBapi()
app.connect('127.0.0.1', 7497, 1)
app.run()
但是在下面收到一条消息:
ERROR -1 502 Couldn't connect to TWS. Confirm that "Enable ActiveX and Socket EClients"
is enabled and connection port is the same as "Socket Port" on the
TWS "Edit->Global Configuration...->API->Settings" menu. Live Trading ports:
TWS: 7496; IB Gateway: 4001. Simulated Trading ports for new installations
of version 954.1 or newer: TWS: 7497; IB Gateway: 4002
我打开了我的 TWS 并启用了 activeX,也尝试取消 localhost 限制,但没有帮助。花了一天时间寻找解决方案,但没有运气。可能基本不可能通过colab连接IB?
非常感谢您的帮助,谢谢。