0

I have the following code:

async def main():

    symbols = ['BTCUSDT', 'ETHUSDT', 'BNBUSDT']
    tasks = []

    async with ClientSession() as session:
        for x in symbols:
            task = asyncio.create_task(nested('https://api.binance.com/api/v1/klines?&symbol={0}&interval={1}&limit=300'.format(symbol, tf), session, symbol))
            tasks.append(task)
            responses = await asyncio.gather(*tasks)
            tasks.clear()
            print(tasks)
            await asyncio.sleep(25)

try:
    assert isinstance(loop := asyncio.new_event_loop(), asyncio.ProactorEventLoop)

    async def proactor_wrap(loop_: asyncio.ProactorEventLoop, fut: asyncio.coroutines):
        await fut
        loop_.stop()

    loop.create_task(proactor_wrap(loop, main()))
    loop.run_forever()

except (AssertionError, AttributeError):
    asyncio.run(main())

How can i schedule the function main() to run every x amount of time, for example every 10 minutes or every 2 hours? Can i use the schedule module for this task?

JayK23
  • 287
  • 1
  • 15
  • 49
  • Does this answer your question? [How can I periodically execute a function with asyncio?](https://stackoverflow.com/questions/37512182/how-can-i-periodically-execute-a-function-with-asyncio) – erip Sep 14 '20 at 11:35
  • 1
    You can sleep that interval, or use a crontab job to run your script. I used a function to run every specific hour https://github.com/dhilst/geckones_twitter_bots/blob/master/utils.py#L25, you may tweak it if you need something like that – geckos Sep 14 '20 at 12:19
  • @geckos this is interesting, thanks a lot! – JayK23 Sep 14 '20 at 12:51

0 Answers0