¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

How to handle if I sell stock from TWS while it was bought by API application ?


 

Hi all,

I have a question for a case which I need to handle. During my tests I have experienced the following

a. API application generates a signal to buy and place the order, I keep the inventory of orders(id, action, qty etc) and portfolio(stockId, bought, sold etc)
b. TWS transmits the order and order is executed, orderStatus, execDetails, commissionReport callbacks are called
c. API application waits for a sell signal to be generated
d. At some point I decide to sell stock manually and I close the position on TWS manually.

TWS shows the stock as sold afterwards but in this case, I see that
1. I receive orderStatus callbacks - but the returned orderId is not the ones that I keep so I cannot relate the orderStatus with the existing portfolio of stocks.
2. I receive NO execDetails for this manual order.
3. I receive commissionReport, but again no way to relate it with a stock in my portfolio of API application.?
4. API application generates the sell signal because it does not aware that stocks gone, and make a Short Sell unintentionally

What would be the way to handle manual sells from TWS while the API application is running ??

Thanks in advance.?

Join [email protected] to automatically receive all group messages.