ib-api-reloaded / ib_async

Python sync/async framework for Interactive Brokers API (replaces ib_insync)
BSD 2-Clause "Simplified" License
455 stars 72 forks source link

keepUpToDate does not work for reqHistoricalData #29

Open datamonke1 opened 5 months ago

datamonke1 commented 5 months ago

keepUpToDate does not work. I dont know if it has anything todo with ib.reqMarketDataType(3)

from ib_async import *
util.startLoop()

ib = IB()
ib.connect( )

contract = Stock('IDIA', 'SMART','CHF')
md=ib.reqMktData(contract, '', False, False)
ib.reqMarketDataType(3)

bars=ib.reqHistoricalData(
        contract,
        endDateTime='',
        durationStr='1 D',
        barSizeSetting='1 min',
        whatToShow='MIDPOINT',
        useRTH=True,
        formatDate=1,keepUpToDate=True)

for i in range(1000):
    print(bars[-1])
    ib.sleep(10) 
baichen111 commented 4 months ago

I reproduce your code and it works for me. realtime got updated if keepUpTodate is set to True

from ib_async import *

ib = IB()
ib.connect('127.0.0.1',7496,1)
contract = Stock('IDIA', 'SMART','CHF')

bars=ib.reqHistoricalData(
            contract,
            endDateTime='',
            durationStr='1 D',
            barSizeSetting='1 min',
            whatToShow='MIDPOINT',
            useRTH=True,
            formatDate=1,keepUpToDate=True)
for _ in range(100):
    print(bars[-1])
    ib.sleep(10)

output:

BarData(date=datetime.datetime(2024, 6, 27, 18, 16, tzinfo=zoneinfo.ZoneInfo(key='Asia/Singapore')), open=2.055, high=2.055, low=2.055, close=2.055, volume=-1.0, average=-1.0, barCount=-1) BarData(date=datetime.datetime(2024, 6, 27, 18, 16, tzinfo=zoneinfo.ZoneInfo(key='Asia/Singapore')), open=2.055, high=2.055, low=2.055, close=2.055, volume=-1.0, average=-1.0, barCount=-1) BarData(date=datetime.datetime(2024, 6, 27, 18, 16, tzinfo=zoneinfo.ZoneInfo(key='Asia/Singapore')), open=2.055, high=2.069, low=2.055, close=2.069, volume=-1.0, average=-1.0, barCount=-1) BarData(date=datetime.datetime(2024, 6, 27, 18, 16, tzinfo=zoneinfo.ZoneInfo(key='Asia/Singapore')), open=2.055, high=2.069, low=2.055, close=2.069, volume=-1.0, average=-1.0, barCount=-1) BarData(date=datetime.datetime(2024, 6, 27, 18, 16, tzinfo=zoneinfo.ZoneInfo(key='Asia/Singapore')), open=2.055, high=2.069, low=2.055, close=2.069, volume=-1.0, average=-1.0, barCount=-1) BarData(date=datetime.datetime(2024, 6, 27, 18, 17, tzinfo=zoneinfo.ZoneInfo(key='Asia/Singapore')), open=2.069, high=2.069, low=2.069, close=2.069, volume=-1.0, average=-1.0, barCount=-1) BarData(date=datetime.datetime(2024, 6, 27, 18, 17, tzinfo=zoneinfo.ZoneInfo(key='Asia/Singapore')), open=2.069, high=2.069, low=2.069, close=2.069, volume=-1.0, average=-1.0, barCount=-1)

The time got updated on last bar