robcarver17 / pysystemtrade

Systematic Trading in python
GNU General Public License v3.0
2.66k stars 837 forks source link

Start collecting open interest data? #1341

Open VMatthijs opened 9 months ago

VMatthijs commented 9 months ago

An idea for a potential new feature: collecting open interest data. IB provides it, so it shouldn't be hard at all. Example code:

from ib_insync import *

util.startLoop()
ib = IB()
ib.connect('127.0.0.1', 4001, clientId=666)

ib.reqMarketDataType(3)
contract = Future('R','202403', 'ICEEU')
ticker = ib.reqMktData(contract, '588', False, False, None)
while True:
    ib.sleep(1)
    print(ticker.futuresOpenInterest)

Historical open interest data is also provided by Barchart so it shouldn't be difficult to backfill it.

I can imagine that this data might be relevant for considerations of whether or not to trade a market, and that it could be used as an input to certain trading signals. If you think it would be useful, @robcarver17 , I'm happy to implement it.

robcarver17 commented 9 months ago

Sure could be useful. For implementation, please go slowly adding the required classes bottom up* one PR at a time and ensuring existing framework is respected. Any questions just ask.

[apologies if telling anyone how to suck eggs here]