use ujson to load ticker files 30% faster from disk.
This commit is contained in:
parent
4a39a754f4
commit
0f3339f74f
@ -10,9 +10,16 @@ import arrow
|
|||||||
from freqtrade import misc, constants, OperationalException
|
from freqtrade import misc, constants, OperationalException
|
||||||
from freqtrade.exchange import Exchange
|
from freqtrade.exchange import Exchange
|
||||||
from freqtrade.arguments import TimeRange
|
from freqtrade.arguments import TimeRange
|
||||||
|
import importlib
|
||||||
|
ujson_found = importlib.util.find_spec("ujson")
|
||||||
|
if ujson_found is not None:
|
||||||
|
import ujson
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
if ujson_found is not None:
|
||||||
|
logger.debug('Loaded UltraJson ujson in optimize.py')
|
||||||
|
|
||||||
|
|
||||||
def trim_tickerlist(tickerlist: List[Dict], timerange: TimeRange) -> List[Dict]:
|
def trim_tickerlist(tickerlist: List[Dict], timerange: TimeRange) -> List[Dict]:
|
||||||
if not tickerlist:
|
if not tickerlist:
|
||||||
@ -63,10 +70,16 @@ def load_tickerdata_file(
|
|||||||
if os.path.isfile(gzipfile):
|
if os.path.isfile(gzipfile):
|
||||||
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:
|
||||||
|
if ujson_found is not None:
|
||||||
|
pairdata = ujson.load(tickerdata, precise_float=True)
|
||||||
|
else:
|
||||||
pairdata = json.load(tickerdata)
|
pairdata = json.load(tickerdata)
|
||||||
elif os.path.isfile(file):
|
elif os.path.isfile(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:
|
||||||
|
if ujson_found is not None:
|
||||||
|
pairdata = ujson.load(tickerdata, precise_float=True)
|
||||||
|
else:
|
||||||
pairdata = json.load(tickerdata)
|
pairdata = json.load(tickerdata)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
@ -163,6 +176,9 @@ def load_cached_data_for_updating(filename: str,
|
|||||||
# read the cached file
|
# read the cached file
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
with open(filename, "rt") as file:
|
with open(filename, "rt") as file:
|
||||||
|
if ujson_found is not None:
|
||||||
|
data = ujson.load(file, precise_float=True)
|
||||||
|
else:
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
# remove the last item, because we are not sure if it is correct
|
# remove the last item, because we are not sure if it is correct
|
||||||
# it could be fetched when the candle was incompleted
|
# it could be fetched when the candle was incompleted
|
||||||
|
@ -23,3 +23,10 @@ scikit-optimize==0.5.2
|
|||||||
|
|
||||||
# Required for plotting data
|
# Required for plotting data
|
||||||
#plotly==3.0.0
|
#plotly==3.0.0
|
||||||
|
|
||||||
|
# find first, C search in arrays
|
||||||
|
py_find_1st==1.1.1
|
||||||
|
|
||||||
|
#Load ticker files 30% faster
|
||||||
|
ujson==1.35
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user