我的Python代码在连接到盈透证券时出现错误200

问题描述 投票:0回答:1

我试图扫描一些选项并得到大量错误 200 和根本不存在的警告。比如TSLA罢工177.33!!!知道如何克服这个问题吗?谢谢你。

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

收到一些错误

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')
python python-3.x interactive-brokers python-interactive
1个回答
0
投票

TSLA 罢工价 177.33 存在,这个数字看起来很奇怪,但这是由于期权合约创建后发生的股票分割所致。

关于你的错误,据我所知,有两种类型。


1。为 XYZ 指定的合约描述不明确。

这意味着提供的合同描述不足以唯一标识合同。

TWS API文档建议添加主交易所: 对于某些具有相同代码、货币和交易所的智能路由股票合约,您还需要指定主要交易所属性来唯一定义合约。这应该被定义为合约的本地交易所,并且是适用于所有股票的良好做法

这是一个示例,其中为

ARCA
指定了主交易所
SPY

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

2。未找到该请求的安全定义。

在您的情况下,出现此错误的所有符号都有 5 个字母,大多数以 W 或 T 结尾。这可能意味着这不是股票,而是衍生品,例如认股权证 (W)。如果您仍想请求市场数据,请使用正确的证券类型。对于认股权证,应该是

"WAR"

© www.soinside.com 2019 - 2024. All rights reserved.