From e26bbc7de8e7d7d876a434f16c91d4e60ead393e Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Wed, 13 Nov 2019 19:50:54 +0300 Subject: [PATCH 1/2] Add fix for bibox exchange --- freqtrade/exchange/__init__.py | 1 + freqtrade/exchange/bibox.py | 21 +++++++++++++++++++++ freqtrade/exchange/exchange.py | 7 +++++++ 3 files changed, 29 insertions(+) create mode 100644 freqtrade/exchange/bibox.py diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index c107f7abc..df18bca02 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -15,3 +15,4 @@ from freqtrade.exchange.exchange import (market_is_active, # noqa: F401 symbol_is_pair) from freqtrade.exchange.kraken import Kraken # noqa: F401 from freqtrade.exchange.binance import Binance # noqa: F401 +from freqtrade.exchange.bibox import Bibox # noqa: F401 diff --git a/freqtrade/exchange/bibox.py b/freqtrade/exchange/bibox.py new file mode 100644 index 000000000..1f042c221 --- /dev/null +++ b/freqtrade/exchange/bibox.py @@ -0,0 +1,21 @@ +""" Bibox exchange subclass """ +import logging +from typing import Dict + +from freqtrade.exchange import Exchange + +logger = logging.getLogger(__name__) + + +class Bibox(Exchange): + """ + Bibox exchange class. Contains adjustments needed for Freqtrade to work + with this exchange. + + Please note that this exchange is not included in the list of exchanges + officially supported by the Freqtrade development team. So some features + may still not work as expected. + """ + + # Adjust ccxt exchange API metadata info + _ccxt_has: Dict = {"fetchCurrencies": False} diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 05db45c9b..0dd8c4ff2 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -30,6 +30,9 @@ class Exchange: _config: Dict = {} + # Adjustments to ccxt exchange API metadata info (ccxt exchange `has` options) + _ccxt_has: Dict = {} + # Parameters to add directly to buy/sell calls (like agreeing to trading agreement) _params: Dict = {} @@ -152,6 +155,10 @@ class Exchange: except ccxt.BaseError as e: raise OperationalException(f"Initialization of ccxt failed. Reason: {e}") from e + # Adjust ccxt API metadata info (`has` options) for the exchange + for k, v in self._ccxt_has.items(): + api.has[k] = v + self.set_sandbox(api, exchange_config, name) return api From 6174a5dd55aed41764de24e345e9848312879c56 Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Wed, 13 Nov 2019 20:22:23 +0300 Subject: [PATCH 2/2] Reimplement adjustment of ccxt 'has' with more generic ccxt_config class attribute --- freqtrade/exchange/bibox.py | 5 +++-- freqtrade/exchange/exchange.py | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/freqtrade/exchange/bibox.py b/freqtrade/exchange/bibox.py index 1f042c221..229abe766 100644 --- a/freqtrade/exchange/bibox.py +++ b/freqtrade/exchange/bibox.py @@ -17,5 +17,6 @@ class Bibox(Exchange): may still not work as expected. """ - # Adjust ccxt exchange API metadata info - _ccxt_has: Dict = {"fetchCurrencies": False} + # fetchCurrencies API point requires authentication for Bibox, + # so switch it off for Freqtrade load_markets() + _ccxt_config: Dict = {"has": {"fetchCurrencies": False}} diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 0dd8c4ff2..30868df07 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -30,8 +30,8 @@ class Exchange: _config: Dict = {} - # Adjustments to ccxt exchange API metadata info (ccxt exchange `has` options) - _ccxt_has: Dict = {} + # Parameters to add directly to ccxt sync/async initialization. + _ccxt_config: Dict = {} # Parameters to add directly to buy/sell calls (like agreeing to trading agreement) _params: Dict = {} @@ -94,10 +94,17 @@ class Exchange: self._trades_pagination_arg = self._ft_has['trades_pagination_arg'] # Initialize ccxt objects + ccxt_config = self._ccxt_config.copy() + ccxt_config = deep_merge_dicts(exchange_config.get('ccxt_config', {}), + ccxt_config) self._api = self._init_ccxt( - exchange_config, ccxt_kwargs=exchange_config.get('ccxt_config')) + exchange_config, ccxt_kwargs=ccxt_config) + + ccxt_async_config = self._ccxt_config.copy() + ccxt_async_config = deep_merge_dicts(exchange_config.get('ccxt_async_config', {}), + ccxt_async_config) self._api_async = self._init_ccxt( - exchange_config, ccxt_async, ccxt_kwargs=exchange_config.get('ccxt_async_config')) + exchange_config, ccxt_async, ccxt_kwargs=ccxt_async_config) logger.info('Using Exchange "%s"', self.name) @@ -155,10 +162,6 @@ class Exchange: except ccxt.BaseError as e: raise OperationalException(f"Initialization of ccxt failed. Reason: {e}") from e - # Adjust ccxt API metadata info (`has` options) for the exchange - for k, v in self._ccxt_has.items(): - api.has[k] = v - self.set_sandbox(api, exchange_config, name) return api