mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-02-19 10:50:50 +00:00
remove debug, reduce duplicate code -> init_check, add docs example for save_to_file
This commit is contained in:
@@ -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:
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user