+ def store_database_report(self, date):
+ try:
+ report_query = 'INSERT INTO reports("date", "market_config_id", "debug") VALUES (%s, %s, %s) RETURNING id;'
+ line_query = 'INSERT INTO report_lines("date", "report_id", "type", "payload") VALUES (%s, %s, %s, %s);'
+ cursor = dbs.psql.cursor()
+ cursor.execute(report_query, (date, self.market_id, self.debug))
+ report_id = cursor.fetchone()[0]
+ for date, type_, payload in self.report.to_json_array():
+ cursor.execute(line_query, (date, report_id, type_, payload))
+
+ dbs.psql.commit()
+ cursor.close()
+ except Exception as e:
+ print("impossible to store report to database: {}; {}".format(e.__class__.__name__, e))
+
+ def store_redis_report(self, date):
+ try:
+ for type_, log in self.report.to_json_redis():
+ key = "/cryptoportfolio/{}/{}/{}".format(self.market_id, date.isoformat(), type_)
+ dbs.redis.set(key, log, ex=31*24*60*60)
+ key = "/cryptoportfolio/{}/latest/{}".format(self.market_id, type_)
+ dbs.redis.set(key, log)
+ key = "/cryptoportfolio/{}/latest/date".format(self.market_id)
+ dbs.redis.set(key, date.isoformat())
+ except Exception as e:
+ print("impossible to store report to redis: {}; {}".format(e.__class__.__name__, e))
+