DrH
DrH

Reputation: 3

Having Error 200 in my Python code connecting it to Interactive Brokers

I am trying to scan some options and get a ton of Error 200 and strikes that do not even exist. Such as TSLA Strike 177.33!!! Any idea how to overcome this? Thank you.

def init_contract(symbol):
    contract = Contract()
    contract.symbol = symbol
    contract.currency = "USD"
    if symbol == 'SPX':
        contract.secType = "IND"
        contract.exchange = 'CBOE'
    else:
        contract.secType = "STK"
        contract.exchange = 'SMART'
    return contract
def get_symbols_nasdaq(include_company_data = False):
    ftp = ftplib.FTP("ftp.nasdaqtrader.com")
    ftp.login()
    ftp.cwd("SymbolDirectory")
    
    r = io.BytesIO()
    ftp.retrbinary('RETR nasdaqlisted.txt', r.write)
    
    if include_company_data:
        r.seek(0)
        data = pd.read_csv(r, sep = "|")
        return data

Some errors received

Error 200, reqId 4683: The contract description specified for WCBR is ambiguous., contract: Contract(secType='STK', symbol='WCBR', exchange='SMART', currency='USD')
Error 200, reqId 4684: The contract description specified for WCLD is ambiguous., contract: Contract(secType='STK', symbol='WCLD', exchange='SMART', currency='USD')
Error 200, reqId 4692: No security definition has been found for the request, contract: Contract(secType='STK', symbol='WESTW', exchange='SMART', currency='USD')
Error 200, reqId 4699: No security definition has been found for the request, contract: Contract(secType='STK', symbol='WGSWW', exchange='SMART', currency='USD')
Error 200, reqId 4709: The contract description specified for WINA is ambiguous., contract: Contract(secType='STK', symbol='WINA', exchange='SMART', currency='USD')
Error 200, reqId 4711: The contract description specified for WING is ambiguous., contract: Contract(secType='STK', symbol='WING', exchange='SMART', currency='USD')
Error 200, reqId 4716: No security definition has been found for the request, contract: Contract(secType='STK', symbol='WINVW', exchange='SMART', currency='USD')
Error 200, reqId 4726: No security definition has been found for the request, contract: Contract(secType='STK', symbol='WKSPW', exchange='SMART', currency='USD')
Error 200, reqId 4729: No security definition has been found for the request, contract: Contract(secType='STK', symbol='WLDSW', exchange='SMART', currency='USD')
Error 200, reqId 4734: The contract description specified for WNDY is ambiguous., contract: Contract(secType='STK', symbol='WNDY', exchange='SMART', currency='USD')
Error 200, reqId 4737: The contract description specified for WOOD is ambiguous., contract: Contract(secType='STK', symbol='WOOD', exchange='SMART', currency='USD')
Error 200, reqId 4742: The contract description specified for WRLD is ambiguous., contract: Contract(secType='STK', symbol='WRLD', exchange='SMART', currency='USD')
Error 200, reqId 4770: No security definition has been found for the request, contract: Contract(secType='STK', symbol='XBIOW', exchange='SMART', currency='USD')
Error 200, reqId 4773: No security definition has been found for the request, contract: Contract(secType='STK', symbol='XBPEW', exchange='SMART', currency='USD')
Error 200, reqId 4783: No security definition has been found for the request, contract: Contract(secType='STK', symbol='XFINW', exchange='SMART', currency='USD')
Error 200, reqId 4795: No security definition has been found for the request, contract: Contract(secType='STK', symbol='XOSWW', exchange='SMART', currency='USD')
Error 200, reqId 4822: No security definition has been found for the request, contract: Contract(secType='STK', symbol='YOTAW', exchange='SMART', currency='USD')
Error 200, reqId 4825: No security definition has been found for the request, contract: Contract(secType='STK', symbol='YSBPW', exchange='SMART', currency='USD')
Error 200, reqId 4833: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZAPPW', exchange='SMART', currency='USD')
Error 200, reqId 4834: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZAZZT', exchange='SMART', currency='USD')
Error 200, reqId 4837: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZBZZT', exchange='SMART', currency='USD')
Error 200, reqId 4839: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZCARW', exchange='SMART', currency='USD')
Error 200, reqId 4841: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZCZZT', exchange='SMART', currency='USD')
Error 200, reqId 4845: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZEOWW', exchange='SMART', currency='USD')
Error 200, reqId 4848: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZFOXW', exchange='SMART', currency='USD')
Error 200, reqId 4857: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZJZZT', exchange='SMART', currency='USD')
Error 200, reqId 4862: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZLSWW', exchange='SMART', currency='USD')
Error 200, reqId 4866: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZOOZW', exchange='SMART', currency='USD')
Error 200, reqId 4868: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZPTAW', exchange='SMART', currency='USD')
Error 200, reqId 4873: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZURAW', exchange='SMART', currency='USD')
Error 200, reqId 4876: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZVZZT', exchange='SMART', currency='USD')
Error 200, reqId 4877: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZWZZT', exchange='SMART', currency='USD')
Error 200, reqId 4878: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZXYZ.A', exchange='SMART', currency='USD')
Error 200, reqId 4879: No security definition has been found for the request, contract: Contract(secType='STK', symbol='ZXZZT', exchange='SMART', currency='USD')

Upvotes: 0

Views: 273

Answers (1)

m3cc
m3cc

Reputation: 323

TSLA Strike 177.33 exists, the number looks strange, but it's due to the stock split which happened after the option contract was created.

Regarding your errors, from what I can see, there are two types.


1. The contract description specified for XYZ is ambiguous.

This means the provided contract description is not sufficient to uniquely identify the contract.

TWS API Documentation suggests to add the primary exchange: For certain smart-routed stock contracts that have the same symbol, currency and exchange, you would also need to specify the primary exchange attribute to uniquely define the contract. This should be defined as the native exchange of a contract, and is good practice to include for all stocks.

Here is an example where the primary exchange ARCA is specified for SPY:

contract = Contract()
contract.symbol = "SPY"
contract.secType = "STK"
contract.currency = "USD"
contract.exchange = "SMART"
contract.primaryExchange = "ARCA"

2. No security definition has been found for the request.

In your case, all symbols with this error have 5 letters, most ending with W or T. It likely means this is not a stock, but a derivative, such as warrants (W). If you still want to request the market data, use the correct security type. For warrants it should be "WAR".

Upvotes: 1

Related Questions