backtesting: try to load data with ujson if it exists

This commit is contained in:
Samuel Husso 2018-07-28 21:56:11 +03:00
parent a3d870ad3e
commit cdd8cc551c

View File

@ -1,7 +1,11 @@
# pragma pylint: disable=missing-docstring
import gzip
import json
try:
import ujson as json
except ImportError:
import json
import inspect
import logging
import os
from typing import Optional, List, Dict, Tuple, Any
@ -14,6 +18,14 @@ from freqtrade.arguments import TimeRange
logger = logging.getLogger(__name__)
def json_load(data):
"""Try to load data with ujson"""
if inspect.getfullargspec(json.load)[5].get('precise_float'):
return json.load(data, precise_float=True)
else:
return json.load(data)
def trim_tickerlist(tickerlist: List[Dict], timerange: TimeRange) -> List[Dict]:
if not tickerlist:
return tickerlist
@ -63,11 +75,11 @@ def load_tickerdata_file(
if os.path.isfile(gzipfile):
logger.debug('Loading ticker data from file %s', gzipfile)
with gzip.open(gzipfile) as tickerdata:
pairdata = json.load(tickerdata)
pairdata = json_load(tickerdata)
elif os.path.isfile(file):
logger.debug('Loading ticker data from file %s', file)
with open(file) as tickerdata:
pairdata = json.load(tickerdata)
pairdata = json_load(tickerdata)
else:
return None
@ -163,7 +175,7 @@ def load_cached_data_for_updating(filename: str,
# read the cached file
if os.path.isfile(filename):
with open(filename, "rt") as file:
data = json.load(file)
data = json_load(file)
# remove the last item, because we are not sure if it is correct
# it could be fetched when the candle was incompleted
if data: