Skip to content

Interactive Brokers request_bars issue for CONTFUT #2616

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

Open
tomek-r opened this issue May 8, 2025 · 2 comments
Open

Interactive Brokers request_bars issue for CONTFUT #2616

tomek-r opened this issue May 8, 2025 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@tomek-r
Copy link

tomek-r commented May 8, 2025

Bug Report

When trying to get historical data for CONTFUT asset type, like ES, IB returns error:

[ERROR] TRADER-000.InteractiveBrokersClient-005: Setting end date/time for continuous future security type is not allowed. (code: 10339, req_id=10004).

Expected Behavior

I can download historical data without being forced to specify end_date_time

end_date_time should be optional.

Actual Behavior

Steps to Reproduce the Problem

Try:

import asyncio
import datetime

from nautilus_trader.adapters.interactive_brokers.common import IBContract
from nautilus_trader.adapters.interactive_brokers.historical import HistoricInteractiveBrokersClient

contract = IBContract(
    secType="CONTFUT",
    symbol="NQ",
    exchange="CME",
)

client = HistoricInteractiveBrokersClient(host=host, port=port, client_id=5)
await client.connect()
await asyncio.sleep(2)

instruments = await client.request_instruments(
    contracts=[contract]
)

bars = await client.request_bars(
   bar_specifications=["1-MINUTE-LAST"],
   end_date_time=datetime.datetime(2025, 5, 8),
   duration='1 D',
   tz_name="US/Central",
   contracts=[contract]
)

Try to omit the end_date_time like:

bars = await client.request_bars(
    bar_specifications=["1-MINUTE-LAST"],
    end_date_time='', # or None
    duration='1 D',
    tz_name="US/Central",
    contracts=[contract]
)

You will see a crash in the console.

    endDateTime=end_date_time.strftime("%Y%m%d %H:%M:%S %Z"),
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "nattype.pyx", line 54, in pandas._libs.tslibs.nattype._make_error_func.f
ValueError: NaTType does not support strftime

It is related to #2570

Specifications

  • OS platform: Mac
  • Python version: 3.12.10
  • nautilus_trader version: 1.216.0
@tomek-r tomek-r added the bug Something isn't working label May 8, 2025
@cjdsellers cjdsellers added the help wanted Extra attention is needed label May 13, 2025
@FGU1
Copy link
Contributor

FGU1 commented May 16, 2025

The reason of this issue is a change in IB API behavior since 10.30
https://www.interactivebrokers.com/campus/ibkr-api-page/tws-api-changelog-2/

July 8, 2024

updateIBKR TWS API
Please be aware that endDateTime must be left as an empty string when requesting continuous futures contracts when using the TWS API with Trader Workstation or IB Gateway releases of 10.30 and above.

NT code will have to be modified accordingly.

@faysou
Copy link
Collaborator

faysou commented May 26, 2025

Fixed in my PR, also works with instrument ids like ES.CME or ES.XCME. This was really hard to fix, something that helps though is that it's easy to debug the IB adapter as it's in python.
#2647

@faysou faysou closed this as completed May 26, 2025
@faysou faysou reopened this May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants