data/history minor cleanup
This commit is contained in:
parent
6dc2175e1f
commit
11dce91281
@ -63,12 +63,8 @@ def load_tickerdata_file(
|
|||||||
Load a pair from file, either .json.gz or .json
|
Load a pair from file, either .json.gz or .json
|
||||||
:return tickerlist or None if unsuccesful
|
:return tickerlist or None if unsuccesful
|
||||||
"""
|
"""
|
||||||
path = make_testdata_path(datadir)
|
filename = pair_data_filename(datadir, pair, ticker_interval)
|
||||||
pair_s = pair.replace('/', '_')
|
pairdata = misc.file_load_json(filename)
|
||||||
file = path.joinpath(f'{pair_s}-{ticker_interval}.json')
|
|
||||||
|
|
||||||
pairdata = misc.file_load_json(file)
|
|
||||||
|
|
||||||
if not pairdata:
|
if not pairdata:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -142,11 +138,18 @@ def load_data(datadir: Optional[Path],
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def make_testdata_path(datadir: Optional[Path]) -> Path:
|
def make_datadir_path(datadir: Optional[Path]) -> Path:
|
||||||
"""Return the path where testdata files are stored"""
|
"""Return the path where testdata files are stored"""
|
||||||
return datadir or (Path(__file__).parent.parent / "tests" / "testdata").resolve()
|
return datadir or (Path(__file__).parent.parent / "tests" / "testdata").resolve()
|
||||||
|
|
||||||
|
|
||||||
|
def pair_data_filename(datadir: Optional[Path], pair: str, ticker_interval: str) -> Path:
|
||||||
|
path = make_datadir_path(datadir)
|
||||||
|
pair_s = pair.replace("/", "_")
|
||||||
|
filename = path.joinpath(f'{pair_s}-{ticker_interval}.json')
|
||||||
|
return filename
|
||||||
|
|
||||||
|
|
||||||
def load_cached_data_for_updating(filename: Path, ticker_interval: str,
|
def load_cached_data_for_updating(filename: Path, ticker_interval: str,
|
||||||
timerange: Optional[TimeRange]) -> Tuple[List[Any],
|
timerange: Optional[TimeRange]) -> Tuple[List[Any],
|
||||||
Optional[int]]:
|
Optional[int]]:
|
||||||
@ -209,9 +212,7 @@ def download_pair_history(datadir: Optional[Path],
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
path = make_testdata_path(datadir)
|
filename = pair_data_filename(datadir, pair, ticker_interval)
|
||||||
filepair = pair.replace("/", "_")
|
|
||||||
filename = path.joinpath(f'{filepair}-{ticker_interval}.json')
|
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f'Download history data for pair: "{pair}", interval: {ticker_interval} '
|
f'Download history data for pair: "{pair}", interval: {ticker_interval} '
|
||||||
@ -236,8 +237,9 @@ def download_pair_history(datadir: Optional[Path],
|
|||||||
misc.file_dump_json(filename, data)
|
misc.file_dump_json(filename, data)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
f'Failed to download history data for pair: "{pair}", interval: {ticker_interval}.'
|
f'Failed to download history data for pair: "{pair}", interval: {ticker_interval}. '
|
||||||
|
f'Error: {e}'
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user