Allow adding new additional headers
This commit is contained in:
		| @@ -54,6 +54,9 @@ class Exchange: | |||||||
|     # Parameters to add directly to buy/sell calls (like agreeing to trading agreement) |     # Parameters to add directly to buy/sell calls (like agreeing to trading agreement) | ||||||
|     _params: Dict = {} |     _params: Dict = {} | ||||||
|  |  | ||||||
|  |     # Additional headers - added to the ccxt object | ||||||
|  |     _headers: Dict = {} | ||||||
|  |  | ||||||
|     # Dict to specify which options each exchange implements |     # Dict to specify which options each exchange implements | ||||||
|     # This defines defaults, which can be selectively overridden by subclasses using _ft_has |     # This defines defaults, which can be selectively overridden by subclasses using _ft_has | ||||||
|     # or by specifying them in the configuration. |     # or by specifying them in the configuration. | ||||||
| @@ -169,7 +172,7 @@ class Exchange: | |||||||
|             asyncio.get_event_loop().run_until_complete(self._api_async.close()) |             asyncio.get_event_loop().run_until_complete(self._api_async.close()) | ||||||
|  |  | ||||||
|     def _init_ccxt(self, exchange_config: Dict[str, Any], ccxt_module: CcxtModuleType = ccxt, |     def _init_ccxt(self, exchange_config: Dict[str, Any], ccxt_module: CcxtModuleType = ccxt, | ||||||
|                    ccxt_kwargs: dict = None) -> ccxt.Exchange: |                    ccxt_kwargs: Dict = {}) -> ccxt.Exchange: | ||||||
|         """ |         """ | ||||||
|         Initialize ccxt with given config and return valid |         Initialize ccxt with given config and return valid | ||||||
|         ccxt instance. |         ccxt instance. | ||||||
| @@ -188,6 +191,10 @@ class Exchange: | |||||||
|         } |         } | ||||||
|         if ccxt_kwargs: |         if ccxt_kwargs: | ||||||
|             logger.info('Applying additional ccxt config: %s', ccxt_kwargs) |             logger.info('Applying additional ccxt config: %s', ccxt_kwargs) | ||||||
|  |         if self._headers: | ||||||
|  |             # Inject static headers after the above output to not confuse users. | ||||||
|  |             ccxt_kwargs = deep_merge_dicts({'headers': self._headers}, ccxt_kwargs) | ||||||
|  |         if ccxt_kwargs: | ||||||
|             ex_config.update(ccxt_kwargs) |             ex_config.update(ccxt_kwargs) | ||||||
|         try: |         try: | ||||||
|  |  | ||||||
|   | |||||||
| @@ -108,6 +108,13 @@ def test_init_ccxt_kwargs(default_conf, mocker, caplog): | |||||||
|     assert hasattr(ex._api_async, 'TestKWARG') |     assert hasattr(ex._api_async, 'TestKWARG') | ||||||
|     assert log_has("Applying additional ccxt config: {'TestKWARG': 11, 'TestKWARG44': 11}", caplog) |     assert log_has("Applying additional ccxt config: {'TestKWARG': 11, 'TestKWARG44': 11}", caplog) | ||||||
|     assert log_has(asynclogmsg, caplog) |     assert log_has(asynclogmsg, caplog) | ||||||
|  |     # Test additional headers case | ||||||
|  |     Exchange._headers = {'hello': 'world'} | ||||||
|  |     ex = Exchange(conf) | ||||||
|  |  | ||||||
|  |     assert log_has("Applying additional ccxt config: {'TestKWARG': 11, 'TestKWARG44': 11}", caplog) | ||||||
|  |     assert ex._api.headers == {'hello': 'world'} | ||||||
|  |     Exchange._headers = {} | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_destroy(default_conf, mocker, caplog): | def test_destroy(default_conf, mocker, caplog): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user