remove html. change var names.
This commit is contained in:
parent
66412bfa58
commit
f6b90595fa
@ -6,7 +6,7 @@ Provides pair list fetched from a remote source
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List, Tuple
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from cachetools import TTLCache
|
from cachetools import TTLCache
|
||||||
@ -60,7 +60,7 @@ class RemotePairList(IPairList):
|
|||||||
"""
|
"""
|
||||||
return f"{self.name} - {self._pairlistconfig['number_assets']} pairs from RemotePairlist."
|
return f"{self.name} - {self._pairlistconfig['number_assets']} pairs from RemotePairlist."
|
||||||
|
|
||||||
def fetch_pairlist(self):
|
def fetch_pairlist(self) -> Tuple[List[str], float, str]:
|
||||||
headers = {
|
headers = {
|
||||||
'User-Agent': 'Freqtrade - Remotepairlist',
|
'User-Agent': 'Freqtrade - Remotepairlist',
|
||||||
}
|
}
|
||||||
@ -68,40 +68,35 @@ class RemotePairList(IPairList):
|
|||||||
info = "Pairlist"
|
info = "Pairlist"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(self._pairlist_url, headers=headers,
|
with requests.get(self._pairlist_url, headers=headers,
|
||||||
timeout=self._read_timeout)
|
timeout=self._read_timeout) as response:
|
||||||
content_type = response.headers.get('content-type')
|
content_type = response.headers.get('content-type')
|
||||||
time_elapsed = response.elapsed.total_seconds()
|
time_elapsed = response.elapsed.total_seconds()
|
||||||
|
|
||||||
rsplit = response.text.split("#")
|
if "application/json" in str(content_type):
|
||||||
|
jsonparse = response.json()
|
||||||
if "text/html" in str(content_type):
|
pairlist = jsonparse['pairs']
|
||||||
if len(rsplit) > 1:
|
info = jsonparse.get('info', '')
|
||||||
plist = rsplit[0].strip()
|
|
||||||
plist = json.loads(plist)
|
|
||||||
info = rsplit[1].strip()
|
|
||||||
else:
|
else:
|
||||||
plist = json.loads(rsplit[0])
|
raise OperationalException(
|
||||||
elif "application/json" in str(content_type):
|
'Remotepairlist is not of type JSON abort')
|
||||||
jsonp = response.json()
|
|
||||||
plist = jsonp['pairs']
|
|
||||||
|
|
||||||
info = jsonp.get('info', '')
|
self._refresh_period = jsonparse.get('refresh_period', self._refresh_period)
|
||||||
self._refresh_period = jsonp.get('refresh_period', self._refresh_period)
|
self._pair_cache = TTLCache(maxsize=1, ttl=self._refresh_period)
|
||||||
|
|
||||||
except requests.exceptions.RequestException:
|
except requests.exceptions.RequestException:
|
||||||
self.log_once(f'Was not able to fetch pairlist from:'
|
self.log_once(f'Was not able to fetch pairlist from:'
|
||||||
f' {self._pairlist_url}', logger.info)
|
f' {self._pairlist_url}', logger.info)
|
||||||
|
|
||||||
if self._keep_pairlist_on_failure:
|
if self._keep_pairlist_on_failure:
|
||||||
plist = str(self._last_pairlist)
|
pairlist = self._last_pairlist
|
||||||
self.log_once('Keeping last fetched pairlist', logger.info)
|
self.log_once('Keeping last fetched pairlist', logger.info)
|
||||||
else:
|
else:
|
||||||
plist = ""
|
pairlist = []
|
||||||
|
|
||||||
time_elapsed = 0
|
time_elapsed = 0
|
||||||
|
|
||||||
return plist, time_elapsed, info
|
return pairlist, time_elapsed, info
|
||||||
|
|
||||||
def gen_pairlist(self, tickers: Tickers) -> List[str]:
|
def gen_pairlist(self, tickers: Tickers) -> List[str]:
|
||||||
"""
|
"""
|
||||||
@ -111,7 +106,7 @@ class RemotePairList(IPairList):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
pairlist = self._pair_cache.get('pairlist')
|
pairlist = self._pair_cache.get('pairlist')
|
||||||
time_elapsed = 0
|
time_elapsed = 0.0
|
||||||
|
|
||||||
if pairlist:
|
if pairlist:
|
||||||
# Item found - no refresh necessary
|
# Item found - no refresh necessary
|
||||||
@ -124,11 +119,11 @@ class RemotePairList(IPairList):
|
|||||||
if file_path.exists():
|
if file_path.exists():
|
||||||
with open(filename) as json_file:
|
with open(filename) as json_file:
|
||||||
# Load the JSON data into a dictionary
|
# Load the JSON data into a dictionary
|
||||||
jsonp = json.load(json_file)
|
jsonparse = json.load(json_file)
|
||||||
pairlist = jsonp['pairs']
|
pairlist = jsonparse['pairs']
|
||||||
|
info = jsonparse.get('info', '')
|
||||||
info = jsonp.get('info', '')
|
self._refresh_period = jsonparse.get('refresh_period', self._refresh_period)
|
||||||
self._refresh_period = jsonp.get('refresh_period', self._refresh_period)
|
self._pair_cache = TTLCache(maxsize=1, ttl=self._refresh_period)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"{self._pairlist_url} does not exist.")
|
raise ValueError(f"{self._pairlist_url} does not exist.")
|
||||||
@ -139,7 +134,7 @@ class RemotePairList(IPairList):
|
|||||||
pairlist = self.filter_pairlist(pairlist, tickers)
|
pairlist = self.filter_pairlist(pairlist, tickers)
|
||||||
self._pair_cache['pairlist'] = pairlist.copy()
|
self._pair_cache['pairlist'] = pairlist.copy()
|
||||||
|
|
||||||
if time_elapsed:
|
if time_elapsed != 0.0:
|
||||||
self.log_once(f'{info} Fetched in {time_elapsed} seconds.', logger.info)
|
self.log_once(f'{info} Fetched in {time_elapsed} seconds.', logger.info)
|
||||||
else:
|
else:
|
||||||
self.log_once(f'{info} Fetched Pairlist.', logger.info)
|
self.log_once(f'{info} Fetched Pairlist.', logger.info)
|
||||||
|
Loading…
Reference in New Issue
Block a user