Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ib.qualifyContracts() leads to error in placing orders #120

Open
siteng98 opened this issue Feb 25, 2025 · 1 comment
Open

ib.qualifyContracts() leads to error in placing orders #120

siteng98 opened this issue Feb 25, 2025 · 1 comment

Comments

@siteng98
Copy link

siteng98 commented Feb 25, 2025

After running ib.qualifyContracts() on COIL contracts, it will pop an error when placing orders instead of going through. For some reason it seems to be specific to this contract, tried it on CL and it works fine.

Sample Script:

from ib_async import *

ib = IB()
ib.connect("127.0.0.1", port=7497, clientId=5)

contract_1 = Future(symbol="COIL", lastTradeDateOrContractMonth="202505", exchange="IPE")
ib.qualifyContracts(contract_1)
order_1 = LimitOrder(action="BUY", totalQuantity=1, lmtPrice=70)
ib.placeOrder(contract_1, order_1)

try:
    ib.run()
except KeyboardInterrupt:
    ib.disconnect()

Output:

Error 10330, reqId 26: The expiry date/time format is invalid. The correct format is yyyyMM, yyyyMMdd HH:mm:ss (operator or instrument time zone) or yyyyMMdd-HH:mm:ss (UTC time zone).
Canceled order: Trade(contract=Future(conId=340216162, symbol='COIL', lastTradeDateOrContractMonth='20250331 19:30:00 GB', multiplier='1000', exchange='IPE', currency='USD', localSymbol='COILK5', tradingClass='COIL'), order=LimitOrder(orderId=26, clientId=5, action='BUY', totalQuantity=1, lmtPrice=70), orderStatus=OrderStatus(orderId=26, status='Cancelled', filled=0.0, remaining=0.0, avgFillPrice=0.0, permId=0, parentId=0, lastFillPrice=0.0, clientId=0, whyHeld='', mktCapPrice=0.0), fills=[], log=[TradeLogEntry(time=datetime.datetime(2025, 2, 25, 7, 42, 8, 200539, tzinfo=datetime.timezone.utc), status='PendingSubmit', message='', errorCode=0), TradeLogEntry(time=datetime.datetime(2025, 2, 25, 7, 42, 8, 201539, tzinfo=datetime.timezone.utc), status='Cancelled', message='Error 10330, reqId 26: The expiry date/time format is invalid. The correct format is yyyyMM, yyyyMMdd HH:mm:ss (operator or instrument time zone) or yyyyMMdd-HH:mm:ss (UTC time zone).', errorCode=10330)], advancedError='')

@mattsta
Copy link
Contributor

mattsta commented Feb 25, 2025

It may just require a longer last trade date specification (don't trust the error message, it doesn't know everything and is clearly just a generic response used for any non-matching data their API doesn't like).

The contract spec at the IBKR contract library shows COIL expires on the first day of the month (May 1) but the last trading day is the last day of the previous month, so maybe IBKR requires a full 20250430 as the last trade date to avoid confusion?

You could also try qualifying more details like symbol="COIL" and localSymbol="COILM5" and tradingClass="COIL" — every contract at IBKR has a unique localSymbol value so usually that one is enough to fully qualify a contract without extra details (along with providing the exchange too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants