简体   繁体   English

使用python从交互式经纪人获取帐户摘要详细信息

[英]Get account summary details from interactive brokers using python

I have some questions based on automated trading via IB using python. 我有一些基于使用IB通过IB进行自动交易的问题。

I can access to TWS, but when I am request for account summary I can't put them into constant variables to use it, I only received them as an printing output. 我可以访问交易平台,但是当我要求提供帐户摘要时,我不能将它们放入常量变量中来使用它,我只将它们作为打印输出接收。

Here my code: 这是我的代码:

from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.opt import Connection, message

def error_handler(msg):
    """Handles the capturing of error messages"""
    print "Server Error: %s" % msg

def reply_handler(msg):
    """Handles of server replies"""
    print "Server Response: %s, %s" % (msg.typeName, msg)

if __name__ == "__main__":

    tws_conn = Connection.create(port=4096, clientId=150)
    tws_conn.connect()
    tws_conn.registerAll(reply_handler)

    tws_conn.reqAccountSummary(119, "All", "TotalCashValue")
    time.sleep(4)

The output on the screen(cmd): 屏幕输出(cmd):

Server Response: accountSummary, <accountSummary reqId=119,
account=DU860294, tag=TotalCashValue, value=980232.77, currency=USD>
Server Response: accountSummary, <accountSummary reqId=119,
account=DUC00074, tag=TotalCashValue, value=610528.18, currency=USD>
Server Response: accountSummaryEnd, <accountSummaryEnd reqId=119>

My needed is to put all these informations into variables to use it in my program. 我需要将所有这些信息放入变量以在程序中使用它。

Thanks in advance. 提前致谢。

You can obtain this information via updateAccountValue event too. 您也可以通过updateAccountValue事件获取此信息。 Subscribe for this event using tws_conn.reqAccountUpdates() and you'll receive account related informations in 使用tws_conn.reqAccountUpdates()订阅此事件,您将在中收到与帐户相关的信息

updateAccountValue(string key, string value, string currency, string accountName) 

Then you can filter the messages like key=="TotalCashValue" and convert the value string into a double variable. 然后,您可以过滤消息,例如key ==“ TotalCashValue”并将值字符串转换为double变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM