08 February 2021

Scale Order with Adjustable Stop in TWS API - Interactive Brokers Part 6

Scenario:

I am using Python TWS API. For a Stock, I want to place a Limit Order with 2 Profit Takers and 1 Stop Loss. If Profit Taker 1 is hit, then the stop loss should decrease by the commensurate amount (so after Profit Taker 1 is hit, the stop loss quantity is now updated to be equal to Profit Taker 2 quantity). How to do this by packing this entire set of operation's into 1 order?

Solution:

Lets first experiment this scenario with the TWS GUI. For this we will use the Classic TWS.

03 February 2021

Handling Callback data between threads in TWS API - Interactive Brokers Part 5

Scenario:

After I place a market order using the TWS API, sometimes I do not receive the orderStatus callback for a very unusually long time. How then can I find out the status of the placed order ?

Important notes concerning IBApi.EWrapper.orderStatus :

  • Typically there are duplicate orderStatus messages with the same information that will be received by a client. This corresponds to messages sent back from TWS, the IB server, or the exchange.
  • There is no guarantee that an orderStatus callbacks will be triggered for every change in order status. For example with market orders when the order is accepted and executes immediately, there commonly will not be any corresponding orderStatus callbacks. For that reason it is recommended to monitor the IBApi.EWrapper.execDetails function in addition to IBApi.EWrapper.orderStatus.