aboutsummaryrefslogtreecommitdiff
path: root/store.py
diff options
context:
space:
mode:
Diffstat (limited to 'store.py')
-rw-r--r--store.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/store.py b/store.py
index cd0bf7b..81828f0 100644
--- a/store.py
+++ b/store.py
@@ -7,6 +7,7 @@ import datetime
7import inspect 7import inspect
8from json import JSONDecodeError 8from json import JSONDecodeError
9from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError 9from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError
10import dbs
10 11
11__all__ = ["Portfolio", "BalanceStore", "ReportStore", "TradeStore"] 12__all__ = ["Portfolio", "BalanceStore", "ReportStore", "TradeStore"]
12 13
@@ -530,12 +531,25 @@ class Portfolio:
530 try: 531 try:
531 cls.data.set(r.json(parse_int=D, parse_float=D)) 532 cls.data.set(r.json(parse_int=D, parse_float=D))
532 cls.parse_cryptoportfolio() 533 cls.parse_cryptoportfolio()
534 cls.store_cryptoportfolio()
533 except (JSONDecodeError, SimpleJSONDecodeError): 535 except (JSONDecodeError, SimpleJSONDecodeError):
534 cls.data.set(None) 536 cls.data.set(None)
535 cls.last_date.set(None) 537 cls.last_date.set(None)
536 cls.liquidities.set({}) 538 cls.liquidities.set({})
537 539
538 @classmethod 540 @classmethod
541 def store_cryptoportfolio(cls):
542 if dbs.redis_connected():
543 hash_ = {}
544 for liquidity, repartitions in cls.liquidities.items():
545 hash_[liquidity] = repartitions[cls.last_date.get()]
546 dump = json.dumps(hash_)
547 key = "/cryptoportfolio/repartition/latest"
548 dbs.redis.set(key, dump)
549 key = "/cryptoportfolio/repartition/date"
550 dbs.redis.set(key, cls.last_date.date().isoformat())
551
552 @classmethod
539 def parse_cryptoportfolio(cls): 553 def parse_cryptoportfolio(cls):
540 def filter_weights(weight_hash): 554 def filter_weights(weight_hash):
541 if weight_hash[1][0] == 0: 555 if weight_hash[1][0] == 0: