¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: primary exchange and exchange


 

Liu



When you use a Contract object in the TWS API, you are really defining a
query on IB's contract database. This contract database contains a huge
number of different securities, so if you're only interested in one of those
(for example when you place an order) you need to make sure that the query
expressed by your Contract object identifies a single security.



Now, if you're placing a directed order for a stock, ie to a specific
exchange, then this is usually pretty straightforward: the symbol, the
sectype, the multiplier and the exchange will be enough (for a stock) to
ensure uniqueness (but I don't doubt someone will point out a case where
that fails and you need to supply something else like tradingClass!).



But if you want to send a SMART order, there is a potential problem. You set
exchange="SMART", but IB has more than one SMART routing infrastructure.
Many stocks are traded in both the USA and Europe, and IB has different
SMART routing infrastructures for those two continents (and possibly for
Asia as well).



So you have to supply information that tells IB which SMART router to use:
you can generally do this just by specifying the currency, because stocks
traded in Europe are normally traded in Euros, and those in the US are
traded in USD. But if for some reason you can't or don't want to specify the
currency, then you can specify primaryExchange (instead of or in addition to
the currrency): so primaryExchange="NASDAQ" tells IB to use the USA SMART
routing infrastructure for your order; similarly for your market data
request, it tells IB to send you the best bids and offers across all the
exchanges in the USA SMART routing infrastructure.



So to summarise, primaryExchange is only ever needed when exchange=SMART,
and even then may not be needed if you've supplied enough information in
your contract object to uniquely identify which SMART routing infrastructure
you need.



I probably ought to add that this was certainly the original purpose of
primaryExchange, but possibly it may now also have other uses, so I'd be
interested to learn if anyone has further information on this.



By the way, it's very worthwhile to write a little utility that enables you
to enter the details for a contract query, do a reqContrqactDetails, and
display all the returned contract details in an easily-readable form. This
makes it very easy to find out what's going wrong when you get those nasty
error 200s and the like.



RIchard







From: TWSAPI@... [mailto:TWSAPI@...]
Sent: 01 June 2016 03:09
To: TWSAPI <TWSAPI@...>
Subject: [TWS API] primary exchange and exchange





Hi all, can someone explain me the difference of exchange and primary
exchange.

When I place an order, which kind of exchange must be provided ?

which one is ok to let it be empty, or they both must be proveded ?



Thanks in advance.



Liu



_____

liu.huanjie@...

Join [email protected] to automatically receive all group messages.