IBKR: 未找到与请求的合同相关的安全定义。

huangapple go评论120阅读模式
英文:

IBKR: No security definition has been found for the request, contract:

问题

我是新来的IBKR和其API,下面给出的代码在qualifyContracts方法上出现错误:

  1. 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')
  2. 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')
  3. 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')
  4. Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=1.67, right='C', exchange='CBOE', currency='USD')
  5. Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=3.33, right='C', exchange='CBOE', currency='USD')
  6. Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=5.0, right='C', exchange='CBOE', currency='USD')
  7. Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=6.67, right='C', exchange='CBOE', currency='USD')

下面是给出的代码:

  1. from ib_insync import *
  2. from random import getrandbits
  3. if __name__ == '__main__':
  4. ib = IB()
  5. client_id = getrandbits(5)
  6. print('Connecting with the CLIENT ID = ', client_id)
  7. PORT = 4002
  8. ib.connect('127.0.0.1', PORT, clientId=client_id)
  9. contract = Stock('TSLA', 'SMART', 'USD')
  10. print('Setting Market Data Type')
  11. ib.reqMarketDataType(3)
  12. print('1')
  13. ib.qualifyContracts(contract)
  14. print('CON ID = ', contract.conId)
  15. chains = ib.reqSecDefOptParams(contract.symbol, '', contract.secType, contract.conId)
  16. cboe_chains = [c for c in chains if c.exchange == 'CBOE']
  17. opts = []
  18. for chain in cboe_chains:
  19. print(chain)
  20. for strike in chain.strikes:
  21. print(strike)
  22. option = Option(symbol=chain.tradingClass, lastTradeDateOrContractMonth=chain.expirations[0], strike=strike,
  23. exchange='CBOE', currency='USD', right='C')
  24. opts.append(option)
  25. print(opts)
  26. 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:

  1. 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')
  2. 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')
  3. 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')
  4. Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=1.67, right='C', exchange='CBOE', currency='USD')
  5. Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=3.33, right='C', exchange='CBOE', currency='USD')
  6. Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=5.0, right='C', exchange='CBOE', currency='USD')
  7. Unknown contract: Option(symbol='TSLA', lastTradeDateOrContractMonth='20230303', strike=6.67, right='C', exchange='CBOE', currency='USD')

The code given below:

  1. from ib_insync import *
  2. from random import getrandbits
  3. if __name__ == '__main__':
  4. ib = IB()
  5. client_id = getrandbits(5)
  6. print('Connecting with the CLIENT ID = ', client_id)
  7. PORT = 4002
  8. ib.connect('127.0.0.1', PORT, clientId=client_id)
  9. # contract = Contract(conId=76792991, exchange='SMART',currency='USD')
  10. contract = Stock('TSLA', 'SMART', 'USD')
  11. print('Setting Market Data Type')
  12. ib.reqMarketDataType(3)
  13. print('1')
  14. ib.qualifyContracts(contract)
  15. print('CON ID = ', contract.conId)
  16. chains = ib.reqSecDefOptParams(contract.symbol, '', contract.secType, contract.conId)
  17. cboe_chains = [c for c in chains if c.exchange == 'CBOE']
  18. # # print(cboe_chains)
  19. # contracts = [Option(cboe_chains[0].underlyingConId, c.symbol, c.secType, c.exchange, c.currency, c.strike, c.right,
  20. # c.lastTradeDateOrContractMonth) for c in cboe_chains]
  21. opts = []
  22. for chain in cboe_chains:
  23. print(chain)
  24. for strike in chain.strikes:
  25. print(strike)
  26. option = Option(symbol=chain.tradingClass, lastTradeDateOrContractMonth=chain.expirations[0], strike=strike,
  27. exchange='CBOE', currency='USD', right='C')
  28. opts.append(option)
  29. #
  30. # qualified_contract = ib.qualifyContracts(option)
  31. # print(qualified_contract)
  32. # print('-----------------------------------')
  33. print(opts)
  34. qualified_contract = ib.qualifyContracts(*opts) # Error comes here

答案1

得分: 1

以下是您要翻译的内容:

  1. 我总是使用默认的主要交易所定义合同SMART并不总是按预期工作此外我不确定' CBOE' 是否是IBKR的有效交易所名称请检查
  2. def contract(
  3. symbol, sec_type="STK", currency="USD", exchange="SMART", primaryExchange="ISLAND"
  4. ):
  5. contract = Contract()
  6. contract.symbol = symbol
  7. contract.secType = sec_type
  8. contract.currency = currency
  9. contract.exchange = exchange
  10. # 指定主要交易所属性以避免合同模糊
  11. contract.primaryExchange = primaryExchange
  12. return contract
  13. 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:

  1. def contract(
  2. symbol, sec_type="STK", currency="USD", exchange="SMART", primaryExchange="ISLAND"
  3. ):
  4. contract = Contract()
  5. contract.symbol = symbol
  6. contract.secType = sec_type
  7. contract.currency = currency
  8. contract.exchange = exchange
  9. # Specify the Primary Exchange attribute to avoid contract ambiguity
  10. contract.primaryExchange = primaryExchange
  11. return contract
  12. contract = Stock('TSLA', 'SMART', 'USD', 'NASDAQ')

huangapple
  • 本文由 发表于 2023年3月4日 03:35:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75631221.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定