I'm trying to load historical data. It takes a while, so I thought I could speed it up with asyncio, but it doesn't work. Instead of data, I'm getting timeouts. Here is what I've tried.:?
?
import asyncio
from datetime import date
from ib_async import IB, Forex
async def load(end):
print(f"Loading {end}")
data = await ib.reqHistoricalDataAsync(
contract, endDateTime=end, durationStr="3 D", barSizeSetting="1 min",
whatToShow="MIDPOINT", useRTH=False, formatDate=2, keepUpToDate=False)
print(data[-1])
async def main():
tasks = [asyncio.create_task(load(date(2024, 12, 1))),
asyncio.create_task(load(date(2024, 12, 2)))]
await asyncio.gather(*tasks)
print('All done')
if __name__ == "__main__":
ib = IB()
ib.connect(host='127.0.0.1', port=4001, clientId=1)
contract = Forex("GBPUSD", 'IDEALPRO')
ib.qualifyContracts(contract)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
I don't understand asyncio well, nor how it works within ib_async. So, I'm stuck here. Could anyone point out where I'm wrong??
?
?