From cd2520603ad074256ccae76c380e499000e624fe Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 16 Dec 2024 19:07:01 +0100 Subject: [PATCH] refactor: move json file dumping to separate method --- freqtrade/misc.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/freqtrade/misc.py b/freqtrade/misc.py index 5ea227984..f6287b756 100644 --- a/freqtrade/misc.py +++ b/freqtrade/misc.py @@ -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}"')