【问题标题】:Getting positions of your portfolio using python ibPy library使用 python ibPy 库获取投资组合的位置
【发布时间】:2015-04-14 16:22:55
【问题描述】:

我正在使用 ibpy 来获取我的投资组合的位置。我知道我可以做到:

from ib.opt import ibConnection
tws = ibConnection( host = 'localhost',port= 7496, clientId = 123)
tws.reqAccountUpdates(True,'accountnumber')

然后我应该以某种方式使用updatePortfolio(),但我不知道如何。

谢谢

【问题讨论】:

    标签: python interactive-brokers ibpy


    【解决方案1】:

    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()
    

    【讨论】:

      【解决方案2】:

      还有reqPositions(),顾名思义,它会为您提供您的职位(并且仅提供您的职位,而不是为您提供许多其他信息)。它们将在message.position 消息中返回。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-16
        • 2016-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多