diff options
Diffstat (limited to 'store.py')
-rw-r--r-- | store.py | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -7,6 +7,7 @@ import datetime | |||
7 | import inspect | 7 | import inspect |
8 | from json import JSONDecodeError | 8 | from json import JSONDecodeError |
9 | from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError | 9 | from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError |
10 | import 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: |