import inspect
from json import JSONDecodeError
from simplejson.errors import JSONDecodeError as SimpleJSONDecodeError
+import dbs
__all__ = ["Portfolio", "BalanceStore", "ReportStore", "TradeStore"]
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):