gpt4 book ai didi

python - 使用 python ibPy 库获取你的投资组合的位置

转载 作者:行者123 更新时间:2023-11-28 20:20:56 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com