英文:
IBKR: No security definition has been found for the request, contract:
问题
我是新来的IBKR和其API,下面给出的代码在qualifyContracts
方法上出现错误:
Error 200, reqId 308: No security definition has been found for the request, contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=808.33, right='C', exchange='CBOE', currency='USD')
Error 200, reqId 309: No security definition has been found for the request, contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=816.67, right='C', exchange='CBOE', currency='USD')
Error 200, reqId 310: No security definition has been found for the request, contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=825.0, right='C', exchange='CBOE', currency='USD')
Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=1.67, right='C', exchange='CBOE', currency='USD')
Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=3.33, right='C', exchange='CBOE', currency='USD')
Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=5.0, right='C', exchange='CBOE', currency='USD')
Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=6.67, right='C', exchange='CBOE', currency='USD')
下面是给出的代码:
from ib_insync import *
from random import getrandbits
if __name__ == '__main__':
ib = IB()
client_id = getrandbits(5)
print('Connecting with the CLIENT ID = ', client_id)
PORT = 4002
ib.connect('127.0.0.1', PORT, clientId=client_id)
contract = Stock('TSLA', 'SMART', 'USD')
print('Setting Market Data Type')
ib.reqMarketDataType(3)
print('1')
ib.qualifyContracts(contract)
print('CON ID = ', contract.conId)
chains = ib.reqSecDefOptParams(contract.symbol, '', contract.secType, contract.conId)
cboe_chains = [c for c in chains if c.exchange == 'CBOE']
opts = []
for chain in cboe_chains:
print(chain)
for strike in chain.strikes:
print(strike)
option = Option(symbol=chain.tradingClass, lastTradeDateOrContractMonth=chain.expirations[0], strike=strike,
exchange='CBOE', currency='USD', right='C')
opts.append(option)
print(opts)
qualified_contract = ib.qualifyContracts(*opts) # Error comes here
希望这对你有所帮助。
英文:
I am new in both IBKR and its API, the code given below is giving error on qualifyContracts
method:
Error 200, reqId 308: No security definition has been found for the request, contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=808.33, right='C', exchange='CBOE', currency='USD')
Error 200, reqId 309: No security definition has been found for the request, contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=816.67, right='C', exchange='CBOE', currency='USD')
Error 200, reqId 310: No security definition has been found for the request, contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=825.0, right='C', exchange='CBOE', currency='USD')
Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=1.67, right='C', exchange='CBOE', currency='USD')
Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=3.33, right='C', exchange='CBOE', currency='USD')
Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=5.0, right='C', exchange='CBOE', currency='USD')
Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=6.67, right='C', exchange='CBOE', currency='USD')
The code given below:
from ib_insync import *
from random import getrandbits
if __name__ == '__main__':
ib = IB()
client_id = getrandbits(5)
print('Connecting with the CLIENT ID = ', client_id)
PORT = 4002
ib.connect('127.0.0.1', PORT, clientId=client_id)
# contract = Contract(conId=76792991, exchange='SMART',currency='USD')
contract = Stock('TSLA', 'SMART', 'USD')
print('Setting Market Data Type')
ib.reqMarketDataType(3)
print('1')
ib.qualifyContracts(contract)
print('CON ID = ', contract.conId)
chains = ib.reqSecDefOptParams(contract.symbol, '', contract.secType, contract.conId)
cboe_chains = [c for c in chains if c.exchange == 'CBOE']
# # print(cboe_chains)
# contracts = [Option(cboe_chains[0].underlyingConId, c.symbol, c.secType, c.exchange, c.currency, c.strike, c.right,
# c.lastTradeDateOrContractMonth) for c in cboe_chains]
opts = []
for chain in cboe_chains:
print(chain)
for strike in chain.strikes:
print(strike)
option = Option(symbol=chain.tradingClass, lastTradeDateOrContractMonth=chain.expirations[0], strike=strike,
exchange='CBOE', currency='USD', right='C')
opts.append(option)
#
# qualified_contract = ib.qualifyContracts(option)
# print(qualified_contract)
# print('-----------------------------------')
print(opts)
qualified_contract = ib.qualifyContracts(*opts) # Error comes here
答案1
得分: 1
以下是您要翻译的内容:
我总是使用默认的主要交易所定义合同,SMART并不总是按预期工作。此外,我不确定' CBOE' 是否是IBKR的有效交易所名称。请检查:
def contract(
symbol, sec_type="STK", currency="USD", exchange="SMART", primaryExchange="ISLAND"
):
contract = Contract()
contract.symbol = symbol
contract.secType = sec_type
contract.currency = currency
contract.exchange = exchange
# 指定主要交易所属性以避免合同模糊
contract.primaryExchange = primaryExchange
return contract
contract = Stock('TSLA', 'SMART', 'USD', 'NASDAQ')
英文:
I always define the contract with a default primary exchange, SMART does not work as expected all the time. Also, I am not sure if 'CBOE' is a valid exchange name for IBKR. Check this:
def contract(
symbol, sec_type="STK", currency="USD", exchange="SMART", primaryExchange="ISLAND"
):
contract = Contract()
contract.symbol = symbol
contract.secType = sec_type
contract.currency = currency
contract.exchange = exchange
# Specify the Primary Exchange attribute to avoid contract ambiguity
contract.primaryExchange = primaryExchange
return contract
contract = Stock('TSLA', 'SMART', 'USD', 'NASDAQ')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论