0

The codes are running fine in Ubuntu with ib insync version 0.9.34

I want to switch my codes to windows, and download all packages again including ib insync version to the latest.

When I run the codes, I got RuntimeWarning: coroutine 'dailyPrice' was never awaited

I am not sure whether it is the version change that causes the problem. I run everything fine in Ubuntu machine.

But, the error is pointing to the asyncio part.

async def dailyPrice(collection, symbol, exchange, currency, primary, semaphore):
    async with semaphore:
        TF = ifExist(collection, symbol, primary)
        if TF == False:
            stock = Stock(symbol, exchange, currency, primaryExchange= primary)
            #ib.qualifyContractsAsync(stock)
            assert await ib.reqContractDetailsAsync(stock)
            data = await ib.reqHistoricalDataAsync(
                contract=stock, endDateTime='', durationStr='2 D',
                barSizeSetting='1 day', whatToShow='TRADES',useRTH=True,
                formatDate=2)

            df = util.df(data)
            df['symbol'] = symbol

            try:
                data = pushToDB(df, primary)
            except:
                errors.append(symbol)

            return df

semaphore = asyncio.BoundedSemaphore(20)

async def main():
    return await asyncio.gather(*coros, return_exceptions=True)

if __name__ == '__main__':
    retry = 3
    while (countTicker(collection) < len(stockList)) and (retry > 0):
        ib = IB()
        #ib.setCallback('error', onError)
        ib.connect('127.0.0.1', 4002, clientId=2)

        stockList = findMissing(collection, stockList) #replace the stockList with missing Ticker
        print("Missing {} stocks' data".format(len(stockList)))

        coros = []
        for symbol, exchange in zip(stockList['IB Symbol'], stockList['Exchange']):
            coros.append(dailyPrice(collection, symbol, 'SMART', 'USD', exchange, semaphore))
        try:
            with timeout(3600, exception=RuntimeError):
                loop = asyncio.get_event_loop()
                lst_result = loop.run_until_complete(main())
        except Exception as e:
            print('logging')
            retry += 1

        ib.disconnect()

        retry -= 1
        print("Try remaining {}".format(retry))

        #restore full stockList
        stockList = pd.read_csv('stockList.csv')
        stockList.drop_duplicates(subset=['IB Symbol'], inplace=True)

end = time.time()
print(end - start)
JOHN
  • 1,411
  • 3
  • 21
  • 41
  • complete set of codes:https://github.com/kychanbp/downloadFundamentals/blob/master/downloadHistoricalData.py – JOHN Jun 13 '19 at 06:23
  • 1
    Could you try to comment out the `with timeout(...):` line and see if it helps? – VPfB Jun 13 '19 at 06:39
  • @VPfB It works now..But why..... – JOHN Jun 13 '19 at 06:58
  • `timeout` must be broken on Windows then. I was just guessing what could be a cause that the coroutine did not run. And the only way I could find is when `timeout` occurs immediately. However I do not know the cause why `timeout` fails. I do not use the `ib-api`. – VPfB Jun 13 '19 at 07:42

0 Answers0