Stock transaction tracking over multiple day(connected to Interactive Brokers TWS API)
Project detail
Need a Windows Desktop App, connected to TWS, to track the stock, options & futures buys, and sells from the first buy till the last sell or from the first short sell to the last cover. Buys/Sells can span days/weeks/months. Need to track the Ticker Symbol, Total shares held, average cost, details of each buy/sell (Like time and price), Total profit/loss (Realized + Unrealized), P/L unrealized, P/L realized.
Some background: I am a swing trader and buy/sell the same stock multiple times over the course of days/weeks/months.
Currently, TWS doesn’t display the total profit for the position. Any P/L realized is not shown the next day and also the average cost is based on the current position and new fills and doesn’t keep track of the average cost of all the buys/sells.
An example
Day 1: Buy 2000 shares of ABC at 10/share. The average cost is $10. P/L realized is 0. Total P/L is based on the current price(should be able to get real-time quotes from TWS respecting the pacing violations) and the current average cost. Unrealized is total – unrealized.
Day 2 : Sell 500 share at $12/share. Average cost is now 9.33 (((2000*10) – (500*12)/(1500)). Realized is $1000, Total P/L is ((Current price – current average cost(9.33))) * current share held(1500)). Unrealized is total – realized. So let’s say the stock falls ot 9.33, total P/L is 0, Realized is 1000, Unrealized is -1000.
Day 3: Buy 100 Shares at $11/share. Average cost is now 9.43((9.33 * 1500) + (100*1100)). Realized doesn’t change. Total and unrealized P/L based on the Real-time quotes.
Day 4: Sell all 1600 at $12. (Total and realized is (12-9.43)*1600). Unrealized is 0. It should remain visible for that day and should move to a historical tab at the start of trading on the next day.
When I click on the historical tab, it should display all the buys/sells and should be accessible for a configurable period( I am thing 1 year).
When I click on the stock (there should be a + sign before the stock, to indicate that the stock was bought/sold multiple times during the configurable period (definition of configurable period below).), it expands and shows all the buys and sells including date/time and price. All the buys/sells that happen in a configurable period are bunched together and shown as a single entry, with price being the average of all the buys/sells but should again be expandable to further display the details of each individual transaction. The only exception is there has been a closing transaction during that period, then it needs to be separated out. So, if configured the time period to be 5 minutes, and make 4 buys of 100 shares with a price of 9.95, 10.12, 10.05, 9.88, it should be shown as a single buy of 400 shares @ $10 each. However, if I sell some. let’s say after 2 buys, then the first 2 buys are shown together, then the sell, and then the next 2 buys, with the ability to drill down further for the individual buys/sells.
Also, it should use the WEB API to get the transactions in case the app wasn’t started along with the TWS.
Realized P/L calculation should be configurable, Last In First Out or Lowest Cost First.
Display lines should alternate between different colors so as tell the two different lines apart or have a thin line between each entry.
Will need well-documented/commented source code as part of the deliverable.