我正在使用 ibpy 来获取我的投资组合的头寸。我明白我能做到:
from ib.opt import ibConnection
tws = ibConnection( host = 'localhost',port= 7496, clientId = 123)
tws.reqAccountUpdates(True,'accountnumber')
然后我应该以某种方式使用 updatePortfolio()
,但我不知道如何使用。
谢谢
最佳答案
tws.reqAccountUpdates(True,'accountnumber')
当您可能认为它是一个变量时,将发送字符串“acctnumber”。请注意,我发送的字符串是我的真实(假)帐号。
然后您需要为您感兴趣的消息注册一个回调。
from ib.opt import ibConnection, message
def acct_update(msg):
print(msg)
con = ibConnection(clientId=1)
con.register(acct_update,
message.updateAccountValue,
message.updateAccountTime,
message.updatePortfolio)
con.connect()
con.reqAccountUpdates(True,'DU000000')
#don't forget to disconnect somehow when done
#con.disconnect()
关于python - 使用 python ibPy 库获取你的投资组合的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632515/