mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-02-08 07:10:28 +00:00
refactor: move json file dumping to separate method
This commit is contained in:
@@ -19,6 +19,15 @@ from freqtrade.enums import SignalTagType, SignalType
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def dump_json_to_file(file_obj: TextIO, data: Any) -> None:
|
||||
"""
|
||||
Dump JSON data into a file object
|
||||
:param file_obj: File object to write to
|
||||
:param data: JSON Data to save
|
||||
"""
|
||||
rapidjson.dump(data, file_obj, default=str, number_mode=rapidjson.NM_NATIVE)
|
||||
|
||||
|
||||
def file_dump_json(filename: Path, data: Any, is_zip: bool = False, log: bool = True) -> None:
|
||||
"""
|
||||
Dump JSON data into a file
|
||||
@@ -35,12 +44,12 @@ def file_dump_json(filename: Path, data: Any, is_zip: bool = False, log: bool =
|
||||
logger.info(f'dumping json to "{filename}"')
|
||||
|
||||
with gzip.open(filename, "wt", encoding="utf-8") as fpz:
|
||||
rapidjson.dump(data, fpz, default=str, number_mode=rapidjson.NM_NATIVE)
|
||||
dump_json_to_file(fpz, data)
|
||||
else:
|
||||
if log:
|
||||
logger.info(f'dumping json to "{filename}"')
|
||||
with filename.open("w") as fp:
|
||||
rapidjson.dump(data, fp, default=str, number_mode=rapidjson.NM_NATIVE)
|
||||
dump_json_to_file(fp, data)
|
||||
|
||||
logger.debug(f'done json to "{filename}"')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user