From 40d0fa279e0745b33676f21cdc8b496ebd301cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 2 May 2018 01:50:46 +0200 Subject: Store last cryptoportfolio repartition to redis --- store.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'store.py') 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): -- cgit v1.2.3