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

标签 python interactive-brokers ibpy

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

相关文章:

python - 获取 os.walk 命中 abspath

python - 如何在 Django 中更改 JsonResponse 的状态

python - ibpy 交互式经纪商的 python api 不适用于下订单

algorithmic-trading - IBPY 获取正确的历史成交量数据

python - "hashable"的类型提示

Python:如何在数组中以 "n"为步长选择性地切换 boolean 元素?

java - 我如何使用 Interactive Brokers Java API 检测定单何时成交?

r - reqExecutions IBrokers软件包

python - 下单后如何获取盈透证券(IBPY)的交易价格和佣金?

interactive-brokers - 在盈透证券 API 中获取上市期权和 future 的参数