ibc.closeAll() not working when a ticker is specified

I haven't been able to successfully close a position using


It only works if I don't specify a ticker. i.e


Also, If it is not too much to ask, I would like to suggest two additional functionalities that i think would be very useful.

  1. Ability to submit orders with "Adaptive IBALGO" order type- This would help ensure better execution price.
  2. Ability to query margin requirement before submitting orders- As IB changes it's margin requirement very often this would help to prevent margin calls.

Please read the IBcontroller docs carefully!

To close all open positions of a symbol use

ticker = "AAPL";
// or
// ticker = Name();
// or ...

ibc.CloseAllOpenPositions( ticker );

As aside as for canceling all pending orders

I have The same problem as daredamy.


works fine, but




doesnt do anything.

Thanks, fxshrat

Did you try ibc.CloseAllOpenPositions( ticker ) and verify that it works?

Your posts are missing crucial information required to help you, like for example TWS VERSION that you are using. IB has long "tradition" of breaking things that were working.

I am using TWS Build 972.1p Aug 17 2018 (Stable Version)
Java Version 1.8.0_152
OS Windows 10

I tried the following:

SVKey = Name()+NumToStr(GetChartID(),1.0,False);
Transmit = True;
ibc = GetTradingInterface("IB"); 
BuyOrderID = StaticVarGetText(SVKey+"BuyOrderID");
SellOrderID = StaticVarGetText(SVKey+"SellOrderID"); 
ticker="FDAX MAR 19-DTB-FUT-EUR";


if( Buytrigger ) 
BuyOrderID= ibc.ModifyOrder( BuyOrderID, ticker, "Buy", Contracts, "MKT", 0, 0, "Day", Transmit); 

if( SellTrigger ) 
SellORderID = ibc.ModifyOrder( SellORderID , ticker, "Sell", Contracts, "MKT", 0, 0, "Day", Transmit); 

ibc.CloseAllOpenPositions();								//1.Try
//ibc.CloseAllOpenPositions(ticker);						//2.Try
//ibc.CloseAllOpenPositions("FDAX MAR 19-DTB-FUT-EUR");		//3.Try
//ibc.CloseAllOpenPositions("Name()");						//4.Try

Buying and Selling with this code works, but not CloseAll.

From the code I can see that your are using DTB futures. Did you try on plain US stock symbols?

I tried with german stock symbols ("BMW-SMART-STK-EUR").
There it is the same. Buying and Selling via AB is no problem, but CloseAllPositions
doesnt work. I cant try with US stocks, because I dont have the data-subscription.