diff --git a/docs/includes/pairlists.md b/docs/includes/pairlists.md index 950f51f99..a07fe5d29 100644 --- a/docs/includes/pairlists.md +++ b/docs/includes/pairlists.md @@ -208,7 +208,42 @@ In "append" mode, the retrieved pairlist is added to the original pairlist. All The `pairlist_url` option specifies the URL of the remote server where the pairlist is located, or the path to a local file (if file:/// is prepended). This allows the user to use either a remote server or a local file as the source for the pairlist. -The `save_to_file` option, when provided with a valid filename, saves the processed pairlist to that file in JSON format. This option is optional, and by default, the pairlist is not saved. +The `save_to_file` option, when provided with a valid filename, saves the processed pairlist to that file in JSON format. This option is optional, and by default, the pairlist is not saved to a file. + +??? Note + Example: + + `save_to_file` can be used to save the pairlist to a file with Bot1: + + ```json + "pairlists": [ + { + "method": "RemotePairList", + "mode": "whitelist", + "pairlist_url": "https://example.com/pairlist", + "number_assets": 10, + "refresh_period": 1800, + "keep_pairlist_on_failure": true, + "read_timeout": 60, + "save_to_file": "user_data/filename.json" + } + ] + ``` + + This saved pairlist file can be loaded by Bot2, or any additional bot with this configuration: + + ```json + "pairlists": [ + { + "method": "RemotePairList", + "mode": "whitelist", + "pairlist_url": "file:///user_data/filename.json", + "number_assets": 10, + "refresh_period": 10, + "keep_pairlist_on_failure": true, + } + ] + ``` The user is responsible for providing a server or local file that returns a JSON object with the following structure: diff --git a/freqtrade/plugins/pairlist/RemotePairList.py b/freqtrade/plugins/pairlist/RemotePairList.py index 079ff49b6..ea0652575 100644 --- a/freqtrade/plugins/pairlist/RemotePairList.py +++ b/freqtrade/plugins/pairlist/RemotePairList.py @@ -185,31 +185,27 @@ class RemotePairList(IPairList): try: pairlist = self.process_json(jsonparse) except Exception as e: - - if self._init_done: - pairlist = self.return_last_pairlist() - logger.warning(f'Error while processing JSON data: {type(e)}') - else: - raise OperationalException(f'Error while processing JSON data: {type(e)}') - + pairlist = self.init_check(f'Failed processing JSON data: {type(e)}') else: - if self._init_done: - self.log_once(f'Error: RemotePairList is not of type JSON: ' - f' {self._pairlist_url}', logger.info) - pairlist = self.return_last_pairlist() - else: - raise OperationalException('RemotePairList is not of type JSON, abort.') + pairlist = self.init_check(f'RemotePairList is not of type JSON: ' + f' {self._pairlist_url}') except requests.exceptions.RequestException: - self.log_once(f'Was not able to fetch pairlist from:' - f' {self._pairlist_url}', logger.info) - - pairlist = self.return_last_pairlist() + pairlist = self.init_check(f'Was not able to fetch pairlist from:' + f' {self._pairlist_url}') time_elapsed = 0 return pairlist, time_elapsed + def init_check(self, error: str): + if self._init_done: + self.log_once("Error: " + error, logger.info) + pairlist = self.return_last_pairlist() + else: + raise OperationalException(error) + return pairlist + def gen_pairlist(self, tickers: Tickers) -> List[str]: """ Generate the pairlist @@ -242,15 +238,10 @@ class RemotePairList(IPairList): jsonparse = rapidjson.load(json_file, parse_mode=CONFIG_PARSE_MODE) pairlist = self.process_json(jsonparse) except Exception as e: - if self._init_done: - pairlist = self.return_last_pairlist() - logger.warning(f'Error while processing JSON data: {type(e)}') - logger.debug(f'Error while processing JSON data: {e}') - else: - raise OperationalException('Error while processing' - f'JSON data: {type(e)}') + pairlist = self.init_check(f'processing JSON data: {type(e)}') else: - raise ValueError(f"{self._pairlist_url} does not exist.") + pairlist = self.init_check(f"{self._pairlist_url} does not exist.") + else: # Fetch Pairlist from Remote URL pairlist, time_elapsed = self.fetch_pairlist()