Zanam
Zanam

Reputation: 4807

New to Python: Interactive Broker API function

I came across this code in python: https://github.com/blampe/IbPy/blob/master/demo/example_opt

When I walk through the debugger and debugger is at location:

con.reqAccountUpdates(1, '')

The console automatically prints the account details. How do I instead dump those details in a variable or in a file instead.

Upvotes: 1

Views: 122

Answers (1)

kevinL
kevinL

Reputation: 57

you need to define an accountInfoHandler first:

def accountInfoHandler(msg):
    global preMargin
    if msg.key=='InitMarginReq':
        preMargin=msg.value

then you initialize the variable and register this handler on Connection

preMargin=-1
con=ibConnection()
con.register(accountInfoHandler,message.updateAccountValue)

last,you call

con.reqAccountUpdates(1, '')
sleep(1)

the variable preMargin will be assigned.

for a set of account variables you can extract, pls refer to this link: https://www.interactivebrokers.com/en/software/api/apiguide/java/updateaccountvalue.htm

Upvotes: 1

Related Questions