Ibapi Error 200: No Security Definition Has Been Found
The ibapi no security definition has been found error (code 200) means the Contract fields you sent matched nothing in IB's database. Fix it by sending the right symbol, secType, exchange and currency, or by resolving the contract with reqContractDetails.
- Error 200 is a contract lookup failure, not a connection, permission or market-data subscription problem.
- Each asset class has a minimum field set: STK needs SMART plus currency, FUT needs an expiry, and forex needs symbol EUR with currency USD on IDEALPRO.
- Use reqContractDetails with a partial Contract to discover the exact conId, localSymbol, tradingClass and exchange instead of guessing.
- Resolve contracts once at startup, cache them by conId, and never place orders with hand-typed contracts.
- For futures, choose the front month from reqContractDetails sorted by expiry, compare YYYYMM expiries by month, and roll a few days before the last trade date, not on it.
What does the ibapi no security definition error 200 mean?
The ibapi no security definition error (200) is returned when TWS or IB Gateway searches its contract database with the fields in your Contract object and finds no match. For ambiguous requests, where several contracts fit and IB will not pick one, the request is also rejected, often with the same code. Either way the problem is in the contract description, not in the session.
It is not a connection problem, and it is not about entitlements. Missing market data subscriptions show up as 354 or 10089, pacing problems as 162, and order permission problems as different order-reject messages. If you get 200, no amount of fixing logins or subscriptions will help.
The error arrives through the error callback with the reqId of the request that carried the bad contract (a market data, historical data, contract details or order id). Use that id to find which of your contracts failed.
Which fields does each contract type need?
IB matches on the combination of fields, so one wrong value is enough to produce zero results. These are the minimum sets that work for the common types.
Note that forex pairs are split: the base currency goes in symbol and the quote currency in currency. Passing symbol='EURUSD' is the most common forex cause of this error.
| Type | secType | Required fields | Typical mistake |
|---|---|---|---|
| Stock | STK | symbol, exchange='SMART', currency | Putting NASDAQ or ARCA in exchange instead of primaryExchange |
| Future | FUT | symbol, exchange, currency, lastTradeDateOrContractMonth | Missing or malformed expiry, or expired month |
| Forex | CASH | symbol='EUR', currency='USD', exchange='IDEALPRO' | symbol='EURUSD' |
| Option | OPT | symbol, exchange='SMART', currency, lastTradeDateOrContractMonth, strike, right, multiplier | right='CALL', string strike, missing tradingClass for weeklies |
| Index | IND | symbol, exchange (e.g. CBOE, CME), currency | Trying to trade it; indices are data only |
from ibapi.contract import Contract
stk = Contract()
stk.symbol, stk.secType, stk.exchange, stk.currency = 'AAPL', 'STK', 'SMART', 'USD'
fx = Contract()
fx.symbol, fx.secType, fx.exchange, fx.currency = 'EUR', 'CASH', 'IDEALPRO', 'USD'
fut = Contract()
fut.symbol, fut.secType, fut.exchange, fut.currency = 'ES', 'FUT', 'CME', 'USD'
fut.lastTradeDateOrContractMonth = '202612' # YYYYMM or YYYYMMDD Why does my stock contract fail on SMART or a non-US exchange?
For multi-listed stocks, keep exchange='SMART' for routing and put the listing venue in primaryExchange (ARCA, NASDAQ, NYSE). Setting exchange='NASDAQ' can work for some symbols but breaks for others. Add primaryExchange only when SMART alone returns several matches, such as the same ticker listed in different places.
Currency must match the listing. A London line needs currency='GBP', Tokyo needs 'JPY' and Hong Kong needs 'HKD'. A ticker that exists in IB's database only in GBP will return 200 if you send USD.
Share classes use IB's own format, not the vendor format. Berkshire class B is 'BRK B' (space) and Brown-Forman B is 'BF B' in IB, not 'BRK.B' or 'BRK-B'. Verify against TWS rather than assuming.
ETFs and ADRs are separate instruments from their underlying ordinary shares, often with a different symbol and currency. Delisted or renamed tickers also vanish from the database, so a symbol that worked last year may now fail.
Why does my futures or options contract return error 200?
Futures are the most frequent source of 200 errors because several fields interact. Check these in order: the expiry format (YYYYMM or YYYYMMDD, as a string), whether that contract month still exists, the exchange, and the multiplier or tradingClass when a root symbol has variants (for example full size versus micro contracts, or different settlement products).
Expired contracts do not resolve unless you set contract.includeExpired = True, and this is only meaningful for contract details and historical data. Also, CONTFUT is a continuous series that can serve historical data but cannot be traded or used for live orders.
Use localSymbol (for example ESZ6) as an alternative to symbol plus expiry. It identifies one exact contract, but the year digit repeats every decade, so prefer conId in code that must stay valid long term.
Exchange naming differs by product and has changed over time. Older tutorials often use GLOBEX, which IB still accepts for some products, but the safest value is the exchange returned by reqContractDetails for that product.
For options, the common causes are: strike sent as a string instead of a float, right sent as 'CALL' rather than 'C' (both may be accepted in some versions, but 'C' or 'P' is safest), a wrong expiry format, a missing multiplier ('100' for standard US equity options), and a missing tradingClass for weekly or non-standard series. Use exchange='SMART'.
from ibapi.contract import Contract
opt = Contract()
opt.symbol = 'AAPL'
opt.secType = 'OPT'
opt.exchange = 'SMART'
opt.currency = 'USD'
opt.lastTradeDateOrContractMonth = '20261218'
opt.strike = 200.0 # float, not '200'
opt.right = 'C' # 'C' or 'P'
opt.multiplier = '100'
# opt.tradingClass = 'AAPL' # set for weeklies / ambiguous series How do I use reqContractDetails to find the exact contract?
Stop guessing and ask IB. Send a partial Contract with symbol, secType and currency, and IB returns every matching contract through the contractDetails callback. The results end with contractDetailsEnd, so wait for it before you use the list.
Read these fields from each ContractDetails: contract.conId, localSymbol, tradingClass, primaryExchange, exchange, multiplier, lastTradeDateOrContractMonth, plus validExchanges and minTick on the details object. Copy them into your order contract, or just set conId (plus consistent secType and exchange).
- Connect to TWS or IB Gateway and start the message loop thread.
- Build a partial Contract with symbol, secType and currency.
- Call reqContractDetails(reqId, contract).
- Collect each result in contractDetails and stop at contractDetailsEnd.
- If more than one row returns, narrow with exchange, multiplier or tradingClass, or pick by expiry.
- Store the chosen conId and reuse it.
import threading, time
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
class App(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
self.results = []
self.done = threading.Event()
def contractDetails(self, reqId, cd):
self.results.append(cd)
def contractDetailsEnd(self, reqId):
self.done.set()
def error(self, reqId, *args):
# Signature differs across ibapi versions; the code is the int among args
print('error', reqId, args)
if 200 in args:
self.done.set()
app = App()
app.connect('127.0.0.1', 7497, clientId=11) # 7497 TWS paper, 4002 Gateway paper
threading.Thread(target=app.run, daemon=True).start()
time.sleep(1)
c = Contract()
c.symbol, c.secType, c.currency, c.exchange = 'ES', 'FUT', 'USD', 'CME'
app.reqContractDetails(1, c)
app.done.wait(10)
for cd in sorted(app.results, key=lambda d: d.contract.lastTradeDateOrContractMonth):
k = cd.contract
print(k.conId, k.localSymbol, k.tradingClass, k.exchange,
k.multiplier, k.lastTradeDateOrContractMonth, cd.minTick, cd.validExchanges)
app.disconnect()How do I resolve and cache contracts so orders never use hand-typed contracts?
Build a pre-flight step that runs at startup, resolves every instrument you need, and fails loudly if any is missing or ambiguous. The rest of the program then uses only the cached, resolved contracts.
For futures, this also prevents rollover failures. Select the front contract by sorting reqContractDetails output on expiry and taking the first one that has not expired.
Expiry codes come in two shapes, so compare them differently. A YYYYMMDD code is compared as a full date. A YYYYMM code is compared by month, so a '202611' contract is still live on 2026-11-16.
Do not wait for the last trade date to roll. Liquidity in index futures such as ES typically migrates to the next quarterly month about a week before expiry, and trading stops at the last trade date. The roll_days buffer below moves you to the next contract earlier, and you should tune it per product.
import datetime as dt, json
from ib_async import IB, Contract, Future, Stock, Forex # or: from ib_insync import ...
def resolve(ib, spec):
cds = ib.reqContractDetails(spec)
if not cds:
raise ValueError(f'unknown contract: {spec}')
return cds
def is_live(expiry, ref):
"""True if the expiry code is on or after the reference date."""
if len(expiry) >= 8: # YYYYMMDD: full date compare
return expiry[:8] >= ref.strftime('%Y%m%d')
return expiry[:6] >= ref.strftime('%Y%m') # YYYYMM: compare by month
def front_future(ib, symbol, exchange, currency='USD', roll_days=7, today=None):
cds = resolve(ib, Future(symbol, exchange=exchange, currency=currency))
ref = (today or dt.date.today()) + dt.timedelta(days=roll_days)
live = [d for d in cds if is_live(d.contract.lastTradeDateOrContractMonth, ref)]
if not live:
raise ValueError(f'no live {symbol} contract')
live.sort(key=lambda d: d.contract.lastTradeDateOrContractMonth.ljust(8, '0'))
return live[0].contract
def test_is_live():
today = dt.date(2026, 11, 16)
assert is_live('202611', today) # month-only code, expires later this month
assert not is_live('202610', today) # previous month
assert is_live('20261120', today) # full date later this month
assert not is_live('20261113', today) # full date already past
assert is_live('20261116', today) # expires today
def preflight(ib, path='contracts.json'):
out = {}
out['AAPL'] = resolve(ib, Stock('AAPL', 'SMART', 'USD'))
if len(out['AAPL']) != 1:
raise ValueError('ambiguous AAPL, add primaryExchange')
out['AAPL'] = out['AAPL'][0].contract
out['EURUSD'] = Forex('EURUSD') # builds symbol=EUR, currency=USD, IDEALPRO
ib.qualifyContracts(out['EURUSD'])
out['ES'] = front_future(ib, 'ES', 'CME')
json.dump({k: v.conId for k, v in out.items()}, open(path, 'w'))
return outDebug checklist: symptom to field to fix
When the ibapi no security definition error persists, work from the table below top to bottom. Each row names the field that most often causes the failure.
| Symptom | Field to check | Fix |
|---|---|---|
| Forex fails | symbol | Use symbol='EUR', currency='USD', exchange='IDEALPRO', secType='CASH' |
| Stock fails on SMART | primaryExchange, currency | Keep exchange='SMART', add primaryExchange, match currency to listing |
| Class share fails | symbol | Use IB format such as 'BRK B' |
| Future fails | lastTradeDateOrContractMonth | Use YYYYMM or YYYYMMDD string for an unexpired month |
| Old future fails | includeExpired | Set includeExpired=True for details or historical data |
| Future returns many or none | exchange, tradingClass, multiplier | Narrow using reqContractDetails output |
| Option fails | strike, right, multiplier, tradingClass | Float strike, 'C' or 'P', '100', set tradingClass for weeklies |
| Index order fails | secType | IND is data only; trade the future or ETF instead |
| Symbol worked before | symbol | Check for delisting or rename in TWS |
| Nothing explains it | TWS version | Update TWS or Gateway and the API client |
Common questions
Is error 200 caused by missing market data subscriptions?
No. Subscription problems return different codes such as 354 (not subscribed) or 10089. Error 200 means the contract lookup itself failed, so fix the Contract fields first.
Can I use only conId in a Contract?
Yes, and it is the least ambiguous option once you have found it. Set conId and keep secType and exchange consistent with the contract details you retrieved, for example SMART for a US stock.
Why does my ib_insync qualifyContracts say ambiguous contract?
More than one contract matched your fields, so IB cannot choose. Add primaryExchange, a specific exchange, currency, multiplier or tradingClass until only one result remains.
Can I trade a CONTFUT or IND contract?
No. Continuous futures and indices are for data only. To trade, resolve a specific futures month with reqContractDetails, or use a tradable product like an ETF.
Why did my futures code break at rollover?
A hard-coded expiry month became expired, so lookups returned nothing. Pick the earliest unexpired contract from reqContractDetails sorted by expiry at every start, and roll several days before the last trade date so you are not left in an expiring, illiquid month.