Support for asyncio via Python

Hi, could I check if there is anyone who has experience using, or knows how to use the Eikon API with the asyncio package for Python?

Best Answer

  • @wesley.ng

    Eikon Data API doesn't provide async interfaces. However, you can run it in an executor. For example:

    import eikon as ek
    import asyncio

    def set_app_key(app_key):
        ek.set_app_key(app_key)

    def get_data(instruments, fields, condition=None):   
        df, err = ek.get_data(instruments,fields,condition)
        return df

    def get_timeseries(instruments, fields, start_date, end_date, interval="daily"):   
        df  = ek.get_timeseries(instruments, fields, start_date, end_date, interval)
        return df

    async def main():    
        loop = asyncio.get_running_loop();     
        await loop.run_in_executor(None, set_app_key,"<App key>")   
        df = await loop.run_in_executor(None, get_data, ["IBM"],["TR.PriceClose"])
        print(df)
        df = await loop.run_in_executor(None, get_timeseries, ["PTT.BK"],"*","2022-01-01","2022-01-31")
        print(df)

    asyncio.run(main())



Answers