erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.85k stars 772 forks source link

Futures Open Interest in Tick Data type? #68

Closed suuuch closed 6 years ago

suuuch commented 6 years ago

I found in this api link http://interactivebrokers.github.io/tws-api/tick_types.html , I found a new data type , Futures Open Interest , and I tried to add this to code, but I failed.

Can I get some help?

erdewit commented 6 years ago

Try something like this:

In [1]: from ib_insync import *
      : util.startLoop()
      : ib = IB().connect(clientId=2)

In [2]: def onUpdate(ticker):
      :     for t in ticker.ticks:
      :         if t.tickType == 86:
      :             print(t)
      : 
      : es = Future('ES', '20180921', 'GLOBEX')
      : ticker = ib.reqMktData(es, '588', False, False, None)
      : ticker.updateEvent += onUpdate

In [3]: 

In [3]: TickData(time=datetime.datetime(2018, 6, 5, 17, 39, 5, 145144, tzinfo=datetime.timezone.utc), tickType=86, price=-1.0, size=225089)
TickData(time=datetime.datetime(2018, 6, 5, 17, 39, 5, 145144, tzinfo=datetime.timezone.utc), tickType=86, price=-1.0, size=225089)
TickData(time=datetime.datetime(2018, 6, 5, 17, 39, 5, 146659, tzinfo=datetime.timezone.utc), tickType=86, price=-1.0, size=225089)
TickData(time=datetime.datetime(2018, 6, 5, 17, 39, 5, 146659, tzinfo=datetime.timezone.utc), tickType=86, price=-1.0, size=225089)
TickData(time=datetime.datetime(2018, 6, 5, 17, 39, 5, 147057, tzinfo=datetime.timezone.utc), tickType=86, price=-1.0, size=225089)
In [3]: 

The open interest is returned in the tick.size.

erdewit commented 6 years ago

Btw, I've just added ticker.futuresOpenInterest for in the next version.

suuuch commented 6 years ago

@erdewit Thank you very much!

AndyR88 commented 11 months ago

How can we retrieve the Daily Historical Open Interest on Futures? Thanks