IB continuous contract symbols

Hi, how are the symbols for the Interactive Brokers' continuous contracts constructed? These series are available in TWS. Thanks!

Hi unkunk2,

Were you able to find a solution to pull/back-test continuous futures contracts on Amibroker from TWS?

Thanks

I've tried variations of CONTFUT and FUT+CONTFUT in Security Type with no success as well as playing around with expirations.IBcontFuts ABcontFut

Without need to check anything further, in quoted text from TWS API description you got pretty obvious answer that it is TWS limitation, not AmiBroker.

DeltaLean, apologies for the late response. I wasn't notified until Tomasz posted his reply today. Have you been able to receive historical continuous contract data from TWS' API?

Hi Tomaz,

Thanks for the reply. If I may expound on the question which is not casting aspersions on either TWS API or AmiBroker but more focused on trying to find a solution for the two programs to work together: Are you aware of a way (or point us in the direction of how) to pull historical continuous futures (not real time data) from TWS API using AmiBroker for back-testing? Is it as simple as me not entering the proper Security type, symbol with expiration or a functionality/feature that isn't widely used in either TWS API or AmiBroker?

RichardScanlan in this post using Esignal seems to have rigged together his own system and am wondering if there is a simpler way that I haven't found in searching the forum.
Esignal Backadjusted Continous Futures - Amibroker Download?

No worries, not yet.

RichardScanlan seems to have the closest solution if we were using Esignal in link attached to my response to Tomaz.

Will keep looking.

If it was me, I’d find a way to export historical contracts, stitch them together, then import into Amibroker if it’s for historical backtestint.

Googled “export IB continuous contract” and like Tomasz posted, they don’t have a feature to do so. Multiple topics pop up for platforms forums with same question.

Instead of chasing something that doesn’t exist. Look to make your own continuous or perhaps try something like Quandl or another data provider that has continuous contracts.

Multiple ways to stitch contracts together and probably beneficial to come up with your own method for rolling contracts.

That may be the way.

I noted in an AB forum link to Tomaz/unkunk2; RichardScanlan has a nice blueprint using Esignal for stitching contracts.

But if you'll notice in this shot from :https://interactivebrokers.github.io/tws-api/basic_contracts.html
IBconFut
"Continuous futures are available from the API with TWS v971 and higher. Continuous futures cannot be used with real time data or to place orders, but only for historical data."

With all the limitations the TWS API has, it seems that continuous futures historical data is available/exists? And if it does, is it as simple as me not entering/stringing together the proper contract.SecType or variations thereof, expiration suffix, or a functionality/feature that isn't widely used in AmiBroker that would allow for pulling the historical data?

Thanks

1 Like

Tomasz, please add this functionality to AmiBroker :pleading_face:

There is not something "missing" to be "added" to AB.

Read this post:

The REAL TIME plugin needs to be able to subscribe to REAL TIME data stream. Real time stream isn't optional, it is necessary. Backfill may be optional, but real-time stream not.

Interactive Brokers staff for some unknown reason decided NOT to support RT steam for continuous futures. And you should address your complaints to Interactive Brokers. Ask THEM to fix their software instead of wresting with workarounds. If TWS was written properly this should JUST WORK. You should just enter ESH8-GLOBEX-CONFUT and it should JUST WORK the same way as any other symbol.

I am not messiah and I can't fix Microsoft work and Interactive Brokers work and everybody's else. They have thousands of programmers. So they should do THEIR job.

Thank you very much for the clarity & closure Tomasz :100: :fireworks:

Sorry because my English is not good. I have successfully connected Ami and the TWS. I'm looking for tickers correctly according to your explanations. But they don't give me the data. says the message "data is not subscribed" "delayed market data is available". Attachment cutout. Some DTB error .... Can you tell me if I can connect with delayed data from the tws or is it necessary if or if real time?.
Luis!

Moderator comment: removed "screenshot" with 90% of blank space

I'd check to make sure you are subscribed to real time data that relates to the products you're looking to trade. I didn't run into any issues as I use TWS/IB US equities/options/futures when I downloaded Amibroker. Perhaps this link will explain it further from @Steve :

The message is OBVIOUS "data is not subscribed". It means exactly what it says.

Solution is to SUBSCRIBE TO RT DATA you are requesting. Delayed data CAN NOT be used.

BTW: next time you post screenshot make sure it DOES NOT contain blank useless space.

1 Like

Just a quick note @DeltaLean @unkunk2, using TWS 978 & AB 6.35 I can retrieve historical intraday data for continuous futures contracts eg CLJ0-NYMEX-CONTFUT or ESH0-GLOBEX-CONTFUT. It works but it's quite limited...

As mentioned in this thread, it's not a real-time stream but only historical data. I can add them to existing real-time databases, but of course they don't update. However whatever Base time interval I choose when I create the database, (e.g selecting EOD or Hourly) I always get 1m historical data thus at most 1 week. I guess as I'm subscribed as a real-time user I'm subject to usual real-time backfill limits, even if contract is only available on an historical basis. Maybe a next version of TWS will take care of that.

If you don't need real-time backfill, but would like to work with historical data, I would suggest the following. The idea is you should NOT use the real-time plugin but get your data another way. So first use some other methods to retrieve historical data from IB, such as DDE as described in TWS DDE for Excel API. It should work with continuous contracts imo. Second, save your historical data in csv format. Third once created a dedicated Amibroker database, simply import csv data. The whole process can obviously be automated.

Of course the easiest way consists in subscribing to a classic data vendor such as eSignal or IQFeed or another download service but i know they can be expensive...

Good luck.

Thank you for the new information @alligator :fireworks:

@alligator, apologies for the delay and thank you for the suggestion. I've found a similar workaround using Ibridgepy to pull historical data into a CSV file. In hindsight, the TWS excel API may have been the better way to go.

if you know your way around Python and can install the IBinsync package it's quite easy to pull CSV files of the CONTFUT historical data.

The following script will grab 6 months of daily data for the 14 continuous contracts listed and store each one in a CSV file by ticker name. You need market data subscription for the relevant exchanges, and importing the individual symbols this way isn't most convenient - if you add the ticker name as a column and combine all the files together into one file (quick python challenge for you), then importing with the Import Wizard in Amibroker is simple and quick.

from ib_insync import *
util.startLoop()
ib = IB()
ib.connect('127.0.0.1', 7496, clientId = 1)

instruments = [
    {
        "ticker": "CL", "exchange": "NYMEX" 
    }, {
        "ticker": "ES", "exchange": "GLOBEX"
    }, {
        "ticker": "EUR", "exchange": "GLOBEX"
    }, {
        "ticker": "GC", "exchange": "NYMEX"
    }, {
        "ticker": "HE", "exchange": "GLOBEX"
    }, {
        "ticker": "HG", "exchange": "NYMEX"
    }, {
        "ticker": "JPY", "exchange": "GLOBEX"
    }, {
        "ticker": "LE", "exchange": "GLOBEX"
    }, {
        "ticker": "NG", "exchange": "NYMEX"
    }, {
        "ticker": "NQ", "exchange": "GLOBEX"
    }, {
        "ticker": "ZC", "exchange": "ECBOT"
    }, {
        "ticker": "ZF", "exchange": "ECBOT"
    }, {
        "ticker": "ZN", "exchange": "ECBOT"
    }, {
        "ticker": "ZS", "exchange": "ECBOT"
    },
]

for instrument in instruments:
    print( instrument['ticker'], instrument['exchange'] )
    contract = ContFuture(instrument['ticker'], instrument['exchange'])

    bars = ib.reqHistoricalData(
        contract, endDateTime='', durationStr='6 M',
        barSizeSetting='1 day', whatToShow='TRADES', useRTH=False)

    # convert to pandas dataframe:
    df = util.df(bars)    
    df.to_csv( instrument['ticker'] + '.csv')
print("Done")

ib.disconnect()

Edit: but yes, it would be super convenient if historical CONTFUT data series could be grabbed for EOD data without needing an external script.

4 Likes