Move load_json to misc

This commit is contained in:
Matthias 2018-12-28 10:04:28 +01:00
parent 065b469a10
commit 27abdd9788
2 changed files with 12 additions and 13 deletions

View File

@ -13,7 +13,6 @@ from typing import Optional, List, Dict, Tuple, Any
import arrow import arrow
from pandas import DataFrame from pandas import DataFrame
import rapidjson
from freqtrade import misc, constants, OperationalException from freqtrade import misc, constants, OperationalException
from freqtrade.data.converter import parse_ticker_dataframe from freqtrade.data.converter import parse_ticker_dataframe
@ -23,15 +22,6 @@ from freqtrade.arguments import TimeRange
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def json_load(data):
"""
load data with rapidjson
Use this to have a consistent experience,
sete number_mode to "NM_NATIVE" for greatest speed
"""
return rapidjson.load(data, number_mode=rapidjson.NM_NATIVE)
def trim_tickerlist(tickerlist: List[Dict], timerange: TimeRange) -> List[Dict]: def trim_tickerlist(tickerlist: List[Dict], timerange: TimeRange) -> List[Dict]:
""" """
Trim tickerlist based on given timerange Trim tickerlist based on given timerange
@ -83,11 +73,11 @@ def load_tickerdata_file(
if gzipfile.is_file(): if gzipfile.is_file():
logger.debug('Loading ticker data from file %s', gzipfile) logger.debug('Loading ticker data from file %s', gzipfile)
with gzip.open(gzipfile) as tickerdata: with gzip.open(gzipfile) as tickerdata:
pairdata = json_load(tickerdata) pairdata = misc.json_load(tickerdata)
elif file.is_file(): elif file.is_file():
logger.debug('Loading ticker data from file %s', file) logger.debug('Loading ticker data from file %s', file)
with open(file) as tickerdata: with open(file) as tickerdata:
pairdata = json_load(tickerdata) pairdata = misc.json_load(tickerdata)
else: else:
return None return None
@ -185,7 +175,7 @@ def load_cached_data_for_updating(filename: Path, tick_interval: str,
# read the cached file # read the cached file
if filename.is_file(): if filename.is_file():
with open(filename, "rt") as file: with open(filename, "rt") as file:
data = json_load(file) data = misc.json_load(file)
# remove the last item, could be incomplete candle # remove the last item, could be incomplete candle
if data: if data:
data.pop() data.pop()

View File

@ -83,6 +83,15 @@ def file_dump_json(filename, data, is_zip=False) -> None:
rapidjson.dump(data, fp, default=str, number_mode=rapidjson.NM_NATIVE) rapidjson.dump(data, fp, default=str, number_mode=rapidjson.NM_NATIVE)
def json_load(data):
"""
load data with rapidjson
Use this to have a consistent experience,
sete number_mode to "NM_NATIVE" for greatest speed
"""
return rapidjson.load(data, number_mode=rapidjson.NM_NATIVE)
def format_ms_time(date: int) -> str: def format_ms_time(date: int) -> str:
""" """
convert MS date to readable format. convert MS date to readable format.