Read trade executions from a TXT (text) file
Author: rajeshu
Creation Date: 9/17/2020 12:40 PM
profile picture

rajeshu

#1
Hi,

I am trying to read executions.txt file of IB
Is there any example of how to do it or which libraries I need to import.

Thanks!
profile picture

Eugene

#2
Hi,

This solution may not support it out of the box but might still give an idea how to adjust your file to import it into WL:

Import real (historical) trades

What's the format of the file? We could probably add support for it in a future release of C.Components.
profile picture

KGo

#3
Historical Trades (HT) is included in the downloadable strategies in the utilities folder. The No Coding version is simplest. All versions may read the file with minimal or no changes. It worked with the IB data I had a few years ago and in fact I added a few data column header titles to match IB's trade report.

Post a text data file with a few trades including column header titles.

One of the advantages with HT is it allows a single buy transaction to be sold in multiple transactions.
profile picture

abegy

#4
Eugene,

This is a standard export format from the IB TWS tool : https://guides.interactivebrokers.com/twsguide/twsguide.htm#usersguidebook/configuretws/configure_auto_export.htm%3FTocPath%3DGlobal%2520Configuration%7C_____2

Default columns are : Symbol,Action (BOT/SLD),Quantity,Price,Time,Date, Exchange,Account,Order Reference,Clearing
profile picture

Eugene

#5
Alexandre, thanks. So TWS supports custom columns: "and custom allows you to define all fields that will be included in the report." That should make it compatible with ImportHistoricalTrades.
profile picture

KGo

#6
QUOTE:
Default columns are : Symbol,Action (BOT/SLD),Quantity,Price,Time,Date, Exchange,Account,Order Reference,Clearing

These default columns are compatible with Historical Trades for daily bars. Intraday bars require the date and time be combined into one date field.

BOT and SLD are not recognized actions in HT. Add these 2 lines to LoadActionDic() routine to recognize them as Long and Sell respectively.
CODE:
Please log in to see this code.


Likewise, if traded, how are Short and Cover trades represented?
profile picture

abegy

#7
With IBKR, there is no order instructions to specify Short and Cover. You are Short automatically when you sell more symbols that you have in your portfolio.
profile picture

KGo

#8
QUOTE:
there is no order instructions to specify Short and Cover

Neither HT nor Import Real (Historical)Trades support closing a long position and simultaneously opening a short position from a single sell order.

HT allows multiple exits on a single entry order. And an exit order will fill as needed against multiple entries. But short trades require short action be input to enter... At least for now.

So, Long trades will work now as in post #6. Short trades must be action labeled as such.
profile picture

Eugene

#9
QUOTE:
Neither HT nor Import Real (Historical)Trades support closing a long position and simultaneously opening a short position from a single sell order.

Right, and at least for me it seems not sensible to support such ambiguous action in "Import Real (Historical) Trades".
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).