我正在使用ibpy来获得我的投资组合的位置。我知道我可以这样做:
from ib.opt import ibConnection
tws = ibConnection( host = 'localhost',port= 7496, clientId = 123)
tws.reqAccountUpdates(True,'accountnumber')然后我应该以某种方式使用updatePortfolio(),但我不知道如何使用。
谢谢
发布于 2015-05-14 00:51:50
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()发布于 2016-01-12 08:35:19
还有reqPositions(),顾名思义,它给你提供你的位置(只给你的位置,而不是给你很多其他信息)。它们将在message.position消息中返回。
https://stackoverflow.com/questions/29632515
复制相似问题