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

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

ibc.closeAll("AAPL")

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

ibc.closeAll()

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.

ibc.CancelAllPendingOrders()

works fine, but

ibc.CloseAllOpenPositions()

or

ibc.CloseAllOpenPositions(ticker)

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:

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

_SECTION_BEGIN("Triggers");
Buytrigger=ParamTrigger("BuyTrigger","BuyTrigger");
SellTrigger=ParamTrigger("SellTrigger","SellTrigger");
CloseAll=ParamTrigger("CloseAll","CloseAll");
_SECTION_END();

_SECTION_BEGIN("Orders");
if( Buytrigger ) 
{ 
BuyOrderID= ibc.ModifyOrder( BuyOrderID, ticker, "Buy", Contracts, "MKT", 0, 0, "Day", Transmit); 
StaticVarSetText(SVKey+"BuyOrderID",BuyOrderID); 
} 

if( SellTrigger ) 
{ 
SellORderID = ibc.ModifyOrder( SellORderID , ticker, "Sell", Contracts, "MKT", 0, 0, "Day", Transmit); 
StaticVarSetText(SVKey+"SellOrderID",SellOrderID); 
} 

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

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.