Basically, I want to use python to query my IB order history and do some analyze afterwards. But I could not find any existing API for me to query these data, does anyone have experience to do this?
Asked
Active
Viewed 6,970 times
6
-
Welcome to StackOverflow! Please read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and [how to give a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This will make it much easier for others to help you. – Aditi Feb 23 '18 at 07:17
-
Interactive Brokers has a documented API. You should attempt to implement a solution and return if you run into specific issues. – Anthony L Feb 23 '18 at 07:18
-
1Yes, I know IB has an API but I could find what I want. – Niucool Ki Feb 26 '18 at 20:07
-
What you want is not done with the api but with account management on the web. https://www.interactivebrokers.com/en/software/etmug/employeetrackmgmt.htm#cshid=employeetrack/etreports/ib_activity_flex.htm – brian Mar 01 '18 at 23:21
-
Thanks, Brian, so there are no program ways to retrieve the order history, right? – Niucool Ki Mar 02 '18 at 06:55
-
You can write a small program to fetch the statements from the internet. You can also log the orders when you make them and when they are filled so you always have a record. – brian Mar 02 '18 at 17:13
-
@NiucoolKi do you found how to solve the issue? – Serhii Didanov Jun 27 '22 at 14:10
2 Answers
8
You have to use flex queries for that purpose. It has full transaction history including trades, open positions, net asset value history and exchange rates.

Istvan Kardkovacs
- 409
- 3
- 5
-
-
@CorneliuMaftuleac https://www.interactivebrokers.com/en/software/allocationfunds/topics/flexqueries.htm – ed22 Nov 02 '20 at 23:25
-
-
1@YevKad you can use the flex web service: https://guides.interactivebrokers.com/ap/advisorportal.htm#flexweb3.htm#kanchor618 You will need to generate a token for this purpose. Here is a good reference how to create a web service token: https://webhelp.tradingdiarypro.com/web_service_import.htm – Istvan Kardkovacs Sep 16 '22 at 22:50
3
TWS API doesn't have this functionality. You can't retreive order history, but you can get open orders using recOpenOrders request and capture executions in realtime by listening to execDetails event - just write them to a file and analyse aftewards.

VictorS
- 201
- 1
- 3
-
After searching in the API to find this functionality and spent a lot of time, I stopped now. Useful answer (I voted up) – Gab2021 Aug 26 '23 at 10:20