Extract close method for exchange
This commit is contained in:
		| @@ -147,6 +147,9 @@ class Exchange: | |||||||
|         """ |         """ | ||||||
|         Destructor - clean up async stuff |         Destructor - clean up async stuff | ||||||
|         """ |         """ | ||||||
|  |         self.close() | ||||||
|  |  | ||||||
|  |     def close(self): | ||||||
|         logger.debug("Exchange object destroyed, closing async loop") |         logger.debug("Exchange object destroyed, closing async loop") | ||||||
|         if self._api_async and inspect.iscoroutinefunction(self._api_async.close): |         if self._api_async and inspect.iscoroutinefunction(self._api_async.close): | ||||||
|             asyncio.get_event_loop().run_until_complete(self._api_async.close()) |             asyncio.get_event_loop().run_until_complete(self._api_async.close()) | ||||||
|   | |||||||
| @@ -661,6 +661,7 @@ class Hyperopt: | |||||||
|         dump(preprocessed, self.data_pickle_file) |         dump(preprocessed, self.data_pickle_file) | ||||||
|  |  | ||||||
|         # We don't need exchange instance anymore while running hyperopt |         # 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 = None  # type: ignore | ||||||
|         self.backtesting.exchange._api_async = None  # type: ignore |         self.backtesting.exchange._api_async = None  # type: ignore | ||||||
|         # self.backtesting.exchange = None  # type: ignore |         # self.backtesting.exchange = None  # type: ignore | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user