IBC message "The contract description is ambiguous"

howto
Tags: #<Tag:0x00007f2d7a4f9f08>

#1

Hello,

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:

VANECK VECTORS GOLD MINERS E
Underlying GDX
Security Type STK
Currency USD
Exchange SMART
Primary Exchange ARCA
Symbol GDX
Issuer Country US
Stock type ETF

Paul


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

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.


#3

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


#4

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

image


#5

@polomora,

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

MSFT,MSFT-!NASDAQ

If multiple symbols

CSCO,CSCO-!NASDAQ
INTC,INTC-!NASDAQ
GDX,GDX-!ARCA
MSFT,MSFT-!NASDAQ

more info
http://www.amibroker.com/kb/2015/09/29/invalid-symbol-message-for-us-stocks-traded-on-multiple-exchanges-interactive-brokers/


#6

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:

GDX-SMART-STK-USD

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:

GDX-ARCA

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.


#7

Here’s a cool resource somewhat on topic…
http://www.bats.com/us/equities/market_statistics/execution_quality/symbol/?symbol=gdx
-S


#8

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:

MSFT,MSFT-!NASDAQ
GDX,GDX-!ARCA

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?


#9

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).


#10

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

symbolName+"-ARCA"
symbolName+"-NASDAQ"
etc.

Again many thanks,
Paul


#11

This
http://www.amibroker.com/guide/w_information.html
and this
http://www.amibroker.com/guide/afl/getfndata.html


#12

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;

	else
	{
		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, '!');
		}
		else
		{
			oPrimaryExchange = tmpExchange;
		}
	}

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

Paul