I have recently started coding in Python and am trying to accomplish the following using IbPy: (1) create an option and ETF buy order (2) execute the order (4) read the portfolio positions (3) track the PnL of the account every 5 min I have been able to achieve (1) and (2) but I am not able to do the (3) Currently I am using the code: tws_conn = conn.Connection.create(port=7497, clientId=100) tws_conn.register( acct_update, msg.updateAccountValue, msg.updateAccountTime, msg.updatePortfolio) tws_conn.reqAccountUpdates(True,'DU15181') The line: tws_conn.reqAccountUpdates prints the position on the console but I will need to get the market information for each contract by reading their ticker (for ETF) and contract characteristics (for options). Does anyone have a sample python code they can share.
I'll have to dig up some code, but off hand here looks like your last line calling reqAccountUpdates is not registered. Your other msg handlers are handling the callback but doesn't look like it is for account updates.
No..... my book includes NO python code! Quantstart is the best reference for ibpy. Alternatively if you want to use swigibpy then you can check out my blog http://qoppac.blogspot.co.uk/p/code.html (ibswigsystematicexamples). It might be that you can adapt the code in http://qoppac.blogspot.co.uk/2014/05/getting-accounting-data-out-of.html for ibpy. GAT
here's a barebones example of getting orderstatus gist.github.com/audubon/b14eeda1c2cad704b333 You can add calling reqAccountUpdates() and implement updateAccountValue() and updatePortfolio()
I was able to make some progress and I implemented the following: tws_conn.connect() tws_conn.reqAccountUpdates(True,'DU15023') It printed the following on the console though: <updateAccountTime timeStamp=18:21> <updatePortfolio contract=<Packages.IbPy.ib.ext.Contract.Contract object at 0x03627E30>, position=0, marketPrice=52.8449974, marketValue=0.0, averageCost=0.0, unrealizedPNL=0.0, realizedPNL=-17.04, accountName=DU15023> <updateAccountTime timeStamp=18:21> <updatePortfolio contract=<Packages.IbPy.ib.ext.Contract.Contract object at 0x03627E30>, position=0, marketPrice=12.89000035, marketValue=0.0, averageCost=0.0, unrealizedPNL=0.0, realizedPNL=-60.6, accountName=DU15023> <updateAccountTime timeStamp=18:21> <updateAccountTime timeStamp=18:21> How do I gather the above information in an array or any other variable so that I can loop through each position in the portfolio and make a buy or sell decision. I am new to the Python so I need some guidance here guys.
I did the following but it didn't work at all: z = list( tws_conn.reqAccountUpdates(True,'DU15211') ) Any suggestions ?
I don't know what type of object that tws method is returning. I was using list as an example. Did 2rosy's github link have a readme?