Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Sep 19, 2024
1 parent 92bfb07 commit 6ceef5e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions core/models/entity/ohlcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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])

Expand Down

0 comments on commit 6ceef5e

Please sign in to comment.