IBC message "The contract description is ambiguous"

Tags: #<Tag:0x00007f2d7a4f9f08>



I’m writing code to to place buy orders and to automatically update sell STP and LMT orders that are placed with TWS using the IB Controller. I have no problems with all of my current positions, except for two: MSFT and GDX. For these two positions, I get the error message

CloseLongOrder: Last Error 200. The contract description specified for GDX is ambiguous.

The code is

childId1 = ibc.PlaceOrder( symbol, "SELL", quantity, "LMT", exitLimitPrice, 0, orderTime,
     isTransmit, 100, "", 0, ocaGroup );
ibc.Sleep( 200 );
errMessage = ibc.GetLastError(childId1);
_TRACE("CloseLongOrder: Last Error " + errMessage);

I have also tried using suffix “-SMART-STK”, and it makes no difference:

childId1 = ibc.PlaceOrder( symbol+"-SMART-STK", "SELL", quantity, "LMT", exitLimitPrice,
     0, orderTime, isTransmit, 100, "", 0, ocaGroup );

Strange it is only a problem for some symbols, and not for others. For GDX, I’ve checked the symbol definition on TWS:

Underlying GDX
Security Type STK
Currency USD
Exchange SMART
Primary Exchange ARCA
Symbol GDX
Issuer Country US
Stock type ETF


Does Amibroker support trades thru IB and data from IQ Feed?

I think it’s the currency your missing off the end.

See: http://www.amibroker.com/kb/2014/12/02/how-to-find-correct-symbol-for-interactive-brokers-data/

The reason it’s only an issue for some symbols is related to the symbol’s uniqueness or otherwise in the IB ecosystem, across all markets and exchanges.


Hello HelixTrader.
I had seen that.
I also tried the suffix -SMART-STK-USD, and it still doesn’t work.
For example MSFT–SMART-STK-USD still gives the same error message


It may be to do with using SMART as the exchange. Have you tried using NASDAQ as in the contract description?




You have to specify primary exchange in IBDictionary.txt file of AmiBroker main directory for symbols traded on multiple exchanges. If you have not such file in there re-install most recent final AmiBroker!

If you want to add primary exchange of a symbol into that file it goes likes this (one line per symbol):

InputSymbol,OutputSymbol, comment (optional)

So for Microsoft


If multiple symbols


more info


Adding SMART-STK makes no sense because it is added already by default.

The thing is that if you don’t specify exchange then “SMART” is used. If you don’t specify currency “USD” is used, if you don’t specify type “STK” is used by default so your GDX automatically becomes:


Trouble is that Interactive Brokers does not know which exchange to pick if symbol is traded on multiple exchanges using same currency. If you do symbol search on IB site: https://www.interactivebrokers.com/en/index.php?f=463 you will find that GDX is traded in multiple currencies but even in USD the GDX stock is traded on multiple exchanges such as LSE and ARCA. So you can’t use “SMART” because IB does not know what you want. You need to specify the exchange to uniquely identify the symbol traded on given exchange to enter the trade. For example:


You may wonder why SMART works for getting quotes - it is because SMART gives you combination feed from multiple sources as you may not care that much from which source you get quotes from, but when it comes to actually entering the trade SMART can become ambiguous and you need to pick the exchange.


Here’s a cool resource somewhat on topic…


fxshrat & Tomasz,

The file IBDictionary.txt is present for my AB installation directory, v6.20.1. The symbol for MSFT is already present in the file. I added an entry for GDX:


It seems that the file is being ignored. When I manually change the code to explicitly use the exchange, it works

childId1 = ibc.PlaceOrder( "GDX-ARCA", "SELL", quantity, "LMT", exitLimitPrice, 0, orderTime, 
              isTransmit, 100, "", 0, ocaGroup );

I’m using v1.3.8 of IBC. Is this the latest version?


You should just follow my advice which is correct, i.e. use GDX-ARCA symbol (you can put in into “Alias” field and use it instead of Name() ).

IBDictionary.txt file is NOT used by IBController, it is used by IB DATA plugin (for RT DATA only).


Ok Tomasz, I understand now. It can’t be used when using EOD data with IB.

What do you mean by “alias”? There is no alias field for ibc.PlaceOrder().

Another solution is to search for error code 200 after calling ibc.PlaceOrder() and retry with


Again many thanks,


and this


Hello Tomasz,

Sorry for the long delay in responding. I added MSFT-NASDAQ" as an alias for MSFT, and I now get an error message
200. No security definition has been found for the request

To make it work, I had to modify the method CWrapper::TickerToContract() to fill in primaryExchange with the exchange value extracted from the alias:

void CWrapper::TickerToContract(LPCTSTR pszTicker, Contract &contract)
	// Added Paul Moore
	CString tmpExchange;

		AfxExtractSubString( oTicker, pszTicker, 0, '-' );
		// Modified Paul Moore
		AfxExtractSubString( tmpExchange, pszTicker, 1, '-');
		//AfxExtractSubString( oExchange, pszTicker, 1, '-');
		AfxExtractSubString( oType, pszTicker, 2, '-');
		AfxExtractSubString( oCurrency, pszTicker, 3, '-');

	// Added Paul Moore
	if( !tmpExchange.IsEmpty() )
		if( tmpExchange[0] == '!' )
			// Remove leading '!', if present
			AfxExtractSubString( oPrimaryExchange, tmpExchange, 1, '!');
			oPrimaryExchange = tmpExchange;

	// Modified Paul Moore
	contract.primaryExchange = oPrimaryExchange; //oExchange == "SMART" ? "" : oExchange;
	//contract.primaryExchange = ""; //oExchange == "SMART" ? "" : oExchange;