Запрашивать сведения о контракте для фьючерсов на NQ ... Ошибка 200, Reqid 9: Определение безопасности не было обнаружено для запроса, контракт: будущее (symbol = 'nq', exchange = 'globex', currence = 'usd') Никаких сведений о контракте не найдено для NQ. Пожалуйста, проверьте свои параметры в шлюзе TWS/IB.
#!/usr/bin/env python3
from ib_insync import IB, Future
from datetime import datetime
import sys
def parse_expiry(expiry):
"""
Parse the expiry string from the contract details.
IB typically provides expiry as YYYYMM or YYYYMMDD.
For comparison, we convert to a datetime object.
"""
if len(expiry) == 6:
# Assume format is YYYYMM; we'll use the 1st of the month for comparison.
try:
return datetime.strptime(expiry, "%Y%m")
except Exception as e:
print(f"Error parsing expiry {expiry}: {e}")
return None
elif len(expiry) == 8:
try:
return datetime.strptime(expiry, "%Y%m%d")
except Exception as e:
print(f"Error parsing expiry {expiry}: {e}")
return None
else:
return None
def main():
# Connect to IBKR Gateway on localhost using port 4002.
ib = IB()
print("Connecting to IBKR Gateway...")
ib.connect('-----------', 4002, clientId=1)
# Create a generic NQ futures contract.
contract = Future()
contract.symbol = "NQ"
contract.secType = "FUT"
contract.exchange = "GLOBEX"
contract.currency = "USD"
# Do not specify lastTradeDateOrContractMonth so that IB returns all available contracts.
print("Requesting contract details for NQ futures...")
details = ib.reqContractDetails(contract)
if not details:
print("No contract details found for NQ. Please verify your parameters in TWS/IB Gateway.")
ib.disconnect()
sys.exit(1)
It would be great if you could help me with this.
tried different exchanges, tried loading different contract symbols, built a test connection.py ,connects to IBKR Gateway
Подробнее здесь: https://stackoverflow.com/questions/794 ... ion-has-be
Интерактивные брокеры IBKR Gateway API - как исправить «Определение безопасности не найдено для запроса»? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение