From 6ceef5efea951faf63fee7cdd9011a4bcf9d8671 Mon Sep 17 00:00:00 2001 From: m5l14i11 Date: Thu, 19 Sep 2024 17:41:18 +0300 Subject: [PATCH] upd --- core/models/entity/ohlcv.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/models/entity/ohlcv.py b/core/models/entity/ohlcv.py index 7c958bbf..2bf375f9 100644 --- a/core/models/entity/ohlcv.py +++ b/core/models/entity/ohlcv.py @@ -39,7 +39,7 @@ def from_list(cls, data: List[Any]) -> "OHLCV": @classmethod def from_dict(cls, data: Dict) -> "OHLCV": - keys = [ + required_keys = { "start", "timestamp", "open", @@ -48,15 +48,22 @@ def from_dict(cls, data: Dict) -> "OHLCV": "close", "volume", "confirm", - ] + } - if any(key not in data for key in keys): - raise ValueError(f"Data dictionary must contain the keys: {keys}") + missing_keys = required_keys - data.keys() + + if missing_keys: + raise ValueError(f"Missing keys in data dictionary: {missing_keys}") - confirmed = ["start", "open", "high", "low", "close", "volume"] - not_confirmed = ["timestamp", "open", "high", "low", "close", "volume"] + if not isinstance(data.get("confirm"), bool): + raise ValueError("'confirm' key must be a boolean value.") - ohlcv_keys = not_confirmed if not data["confirm"] else confirmed + keys_to_use = { + True: ["start", "open", "high", "low", "close", "volume"], + False: ["timestamp", "open", "high", "low", "close", "volume"], + } + + ohlcv_keys = keys_to_use[data["confirm"]] return cls.from_list([data[key] for key in ohlcv_keys])