Switch from ujson to rapidjson

This commit is contained in:
Matthias 2018-12-28 10:01:16 +01:00
parent 98ac2b15ca
commit c955415cc3
5 changed files with 11 additions and 11 deletions

View File

@ -13,7 +13,7 @@ from typing import Optional, List, Dict, Tuple, Any
import arrow
from pandas import DataFrame
import ujson
import rapidjson
from freqtrade import misc, constants, OperationalException
from freqtrade.data.converter import parse_ticker_dataframe
@ -25,11 +25,11 @@ logger = logging.getLogger(__name__)
def json_load(data):
"""
load data with ujson
load data with rapidjson
Use this to have a consistent experience,
otherwise "precise_float" needs to be passed to all load operations
sete number_mode to "NM_NATIVE" for greatest speed
"""
return ujson.load(data, precise_float=True)
return rapidjson.load(data, number_mode=rapidjson.NM_NATIVE)
def trim_tickerlist(tickerlist: List[Dict], timerange: TimeRange) -> List[Dict]:

View File

@ -3,7 +3,6 @@ Various tool function for Freqtrade and scripts
"""
import gzip
import json
import logging
import re
from datetime import datetime
@ -11,6 +10,7 @@ from typing import Dict
import numpy as np
from pandas import DataFrame
import rapidjson
logger = logging.getLogger(__name__)
@ -77,10 +77,10 @@ def file_dump_json(filename, data, is_zip=False) -> None:
if not filename.endswith('.gz'):
filename = filename + '.gz'
with gzip.open(filename, 'w') as fp:
json.dump(data, fp, default=str)
rapidjson.dump(data, fp, default=str, number_mode=rapidjson.NM_NATIVE)
else:
with open(filename, 'w') as fp:
json.dump(data, fp, default=str)
rapidjson.dump(data, fp, default=str, number_mode=rapidjson.NM_NATIVE)
def format_ms_time(date: int) -> str:

View File

@ -46,12 +46,12 @@ def test_common_datearray(default_conf) -> None:
def test_file_dump_json(mocker) -> None:
file_open = mocker.patch('freqtrade.misc.open', MagicMock())
json_dump = mocker.patch('json.dump', MagicMock())
json_dump = mocker.patch('rapidjson.dump', MagicMock())
file_dump_json('somefile', [1, 2, 3])
assert file_open.call_count == 1
assert json_dump.call_count == 1
file_open = mocker.patch('freqtrade.misc.gzip.open', MagicMock())
json_dump = mocker.patch('json.dump', MagicMock())
json_dump = mocker.patch('rapidjson.dump', MagicMock())
file_dump_json('somefile', [1, 2, 3], True)
assert file_open.call_count == 1
assert json_dump.call_count == 1

View File

@ -23,4 +23,4 @@ scikit-optimize==0.5.2
py_find_1st==1.1.3
#Load ticker files 30% faster
ujson==1.35
python-rapidjson==0.6.3

View File

@ -38,7 +38,7 @@ setup(name='freqtrade',
'cachetools',
'coinmarketcap',
'scikit-optimize',
'ujson',
'python-rapidjson',
'py_find_1st'
],
include_package_data=True,