我正在使用 ibPy 在相当新的 ubuntu 机器上连接到 TWS。我已成功登录模拟交易账户并通过 ibPy 界面以编程方式提交买卖订单。
但是,我现在尝试做的不仅仅是提交订单。即,我正在尝试从 TWS 获取更新的头寸。我有兴趣成功运行以下代码:
from time import sleep
from ib.opt import ibConnection, message
def error_handler(msg):
print(msg)
def acct_update(msg):
print(msg)
con = ibConnection(clientId=100)
con.register(acct_update,
message.updateAccountValue,
message.updateAccountTime,
message.updatePortfolio)
con.register(error_handler, "Error")
con.connect()
con.reqAccountUpdates(True, 'DU000000')
sleep(1)
con.disconnect()
但是,执行时出现以下错误:
<error id=-1, errorCode=502, errorMsg=Couldn't connect to TWS.
Confirm that "Enable ActiveX and Socket Clients" is enabled on
the TWS "Configure->API" menu.>
我已确保在 TWS 首选项中确实启用了 ActiveX 和套接字客户端,所以这不是问题。令我惊讶的是,我能够成功提交订单,但无法从 TWS 获得账户更新。有谁知道为什么会发生这种情况?