X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git;a=blobdiff_plain;f=store.py;h=81828f0ae3df4a1c60ea5a287a7b4fe531cacf90;hp=cd0bf7babe2e7240588f4605571365f98096305b;hb=40d0fa279e0745b33676f21cdc8b496ebd301cf8;hpb=30700830b6c0aaaa59c148ebd8edb6931040ed13 diff --git a/store.py b/store.py index cd0bf7b..81828f0 100644 --- a/store.py +++ b/store.py @@ -7,6 +7,7 @@ import datetime import inspect from json import JSONDecodeError from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError +import dbs __all__ = ["Portfolio", "BalanceStore", "ReportStore", "TradeStore"] @@ -530,11 +531,24 @@ class Portfolio: try: cls.data.set(r.json(parse_int=D, parse_float=D)) cls.parse_cryptoportfolio() + cls.store_cryptoportfolio() except (JSONDecodeError, SimpleJSONDecodeError): cls.data.set(None) cls.last_date.set(None) cls.liquidities.set({}) + @classmethod + def store_cryptoportfolio(cls): + if dbs.redis_connected(): + hash_ = {} + for liquidity, repartitions in cls.liquidities.items(): + hash_[liquidity] = repartitions[cls.last_date.get()] + dump = json.dumps(hash_) + key = "/cryptoportfolio/repartition/latest" + dbs.redis.set(key, dump) + key = "/cryptoportfolio/repartition/date" + dbs.redis.set(key, cls.last_date.date().isoformat()) + @classmethod def parse_cryptoportfolio(cls): def filter_weights(weight_hash):