erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.85k stars 775 forks source link

coroutine 'Watchdog.watchAsync' was never awaited #48

Closed radekwlsk closed 6 years ago

radekwlsk commented 6 years ago
/usr/lib/python3.6/socketserver.py:544: RuntimeWarning:

coroutine 'Watchdog.watchAsync' was never awaited

ib_insync 0.9.3

I am getting this warning when using new Watchdog. It uses one of 3 IBs that are connected all the time, to keep TWS alive with ib-controller.

Watchdog and other 2 IBs are run in separate threading.Thread that is the live algorithm using those clients.

First IBController is created:

self.controller = IBController(APP='GATEWAY',  # 'TWS' or 'GATEWAY'
                                   TWS_MAJOR_VRSN=config.get('TWSMajorVersion'),
                                   TRADING_MODE=config.get('TWSTradingMode'),
                                   IBC_INI=config.get('IBCIniPath'),
                                   IBC_PATH=config.get('IBCPath'),
                                   TWS_PATH=config.get('TWSPath'),
                                   LOG_PATH=config.get('IBCLogPath'),
                                   TWSUSERID='',
                                   TWSPASSWORD='',
                                   JAVA_PATH='',
                                   TWS_CONFIG_PATH='')

Then Watchdog is initialized and started:

super().__init__(controller=self.controller,
                 host='127.0.0.1',
                 port='4002',
                 clientId=self.client_id,
                 connectTimeout=connect_timeout,
                 appStartupTime=app_startup_time,
                 appTimeout=app_timeout,
                 retryDelay=retry_delay)
super().start()

Is there anything else that I have to do?

erdewit commented 6 years ago

The warning is likely not something serious but i will look into how it can be avoided.

radekwlsk commented 6 years ago

@erdewit so my initialization of Watchdog is good and it works fine then, yes? Because the TWS freezes for me everyday when run with ib-controller 24/7. I hope it will resolve the problems.

To restart 'manually' is calling Watchdog.scheduleRestart() at predefined hour enough? I would like to restart the ib-controller and therefore IBGateway at 2:30 UTC each day.

erdewit commented 6 years ago

@AfroMetal the watchdog instantiation looks okay. The use of the threading and socketserver module looks a bit troubling in the sense that they do not work well with asyncio so I hope you have thought that through.

For a manual restart, first do watchdog.stop() and then watchdog.scheduleRestart(). In my experience the gateway is restarted at least once a day anyway because of either timeout or error 1100.

radekwlsk commented 6 years ago

@erdewit would you recommend moving to multiprocessing instead of threading?

erdewit commented 6 years ago

@AfroMetal I can't really recommend anything as I have no clue what your project looks like. For myself I prefer asyncio in a single thread and use distex to farm out to other processes.

erdewit commented 6 years ago

This should be no longer a problem.