簡體   English   中英

使用python從交互式經紀人獲取帳戶摘要詳細信息

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

我有一些基於使用IB通過IB進行自動交易的問題。

我可以訪問交易平台,但是當我要求提供帳戶摘要時,我不能將它們放入常量變量中來使用它,我只將它們作為打印輸出接收。

這是我的代碼:

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)

屏幕輸出(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>

我需要將所有這些信息放入變量以在程序中使用它。

提前致謝。

您也可以通過updateAccountValue事件獲取此信息。 使用tws_conn.reqAccountUpdates()訂閱此事件,您將在中收到與帳戶相關的信息

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

然后,您可以過濾消息,例如key ==“ TotalCashValue”並將值字符串轉換為double變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM