0

I have some questions based on automated trading via IB using python.

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

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.

bahaa
  • 11
  • 7
  • There is now a new python api from IB, check this question- https://stackoverflow.com/q/47151737/2855515 – brian Dec 13 '17 at 14:56

1 Answers1

0

You can obtain this information via updateAccountValue event too. Subscribe for this event using tws_conn.reqAccountUpdates() and you'll receive account related informations in

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.

Janos
  • 165
  • 10