Extract close method for exchange

This commit is contained in:
Matthias 2021-02-06 10:22:59 +01:00 committed by crypto_rahino
parent b89744753e
commit f56e63895d
2 changed files with 4 additions and 0 deletions

View File

@ -147,6 +147,9 @@ class Exchange:
"""
Destructor - clean up async stuff
"""
self.close()
def close(self):
logger.debug("Exchange object destroyed, closing async loop")
if self._api_async and inspect.iscoroutinefunction(self._api_async.close):
asyncio.get_event_loop().run_until_complete(self._api_async.close())

View File

@ -665,6 +665,7 @@ class Hyperopt:
dump(preprocessed, self.data_pickle_file)
# We don't need exchange instance anymore while running hyperopt
self.backtesting.exchange.close()
self.backtesting.exchange._api = None # type: ignore
self.backtesting.exchange._api_async = None # type: ignore
# self.backtesting.exchange = None # type: ignore