aboutsummaryrefslogtreecommitdiff
path: root/store.py
diff options
context:
space:
mode:
Diffstat (limited to 'store.py')
-rw-r--r--store.py46
1 files changed, 32 insertions, 14 deletions
diff --git a/store.py b/store.py
index 0c018e0..072d3a2 100644
--- a/store.py
+++ b/store.py
@@ -17,6 +17,7 @@ class ReportStore:
17 17
18 self.print_logs = [] 18 self.print_logs = []
19 self.logs = [] 19 self.logs = []
20 self.redis_status = []
20 21
21 self.no_http_dup = no_http_dup 22 self.no_http_dup = no_http_dup
22 self.last_http = None 23 self.last_http = None
@@ -46,6 +47,10 @@ class ReportStore:
46 self.logs.append(hash_) 47 self.logs.append(hash_)
47 return hash_ 48 return hash_
48 49
50 def add_redis_status(self, hash_):
51 self.redis_status.append(hash_)
52 return hash_
53
49 @staticmethod 54 @staticmethod
50 def default_json_serial(obj): 55 def default_json_serial(obj):
51 if isinstance(obj, (datetime.datetime, datetime.date)): 56 if isinstance(obj, (datetime.datetime, datetime.date)):
@@ -63,6 +68,13 @@ class ReportStore:
63 json.dumps(log, default=self.default_json_serial, indent=" ") 68 json.dumps(log, default=self.default_json_serial, indent=" ")
64 ) 69 )
65 70
71 def to_json_redis(self):
72 for log in (x.copy() for x in self.redis_status):
73 yield (
74 log.pop("type"),
75 json.dumps(log, default=self.default_json_serial)
76 )
77
66 def set_verbose(self, verbose_print): 78 def set_verbose(self, verbose_print):
67 self.verbose_print = verbose_print 79 self.verbose_print = verbose_print
68 80
@@ -91,11 +103,14 @@ class ReportStore:
91 for currency, balance in self.market.balances.all.items(): 103 for currency, balance in self.market.balances.all.items():
92 self.print_log("\t{}".format(balance)) 104 self.print_log("\t{}".format(balance))
93 105
94 self.add_log({ 106 log = {
95 "type": "balance", 107 "type": "balance",
96 "tag": tag, 108 "tag": tag,
97 "balances": self.market.balances.as_json() 109 "balances": self.market.balances.as_json()
98 }) 110 }
111
112 self.add_log(log.copy())
113 self.add_redis_status(log)
99 114
100 def log_tickers(self, amounts, other_currency, 115 def log_tickers(self, amounts, other_currency,
101 compute_value, type): 116 compute_value, type):
@@ -107,15 +122,18 @@ class ReportStore:
107 for currency, amount in amounts.items(): 122 for currency, amount in amounts.items():
108 values[currency] = amount.as_json()["value"] 123 values[currency] = amount.as_json()["value"]
109 rates[currency] = amount.rate 124 rates[currency] = amount.rate
110 self.add_log({ 125 log = {
111 "type": "tickers", 126 "type": "tickers",
112 "compute_value": compute_value, 127 "compute_value": compute_value,
113 "balance_type": type, 128 "balance_type": type,
114 "currency": other_currency, 129 "currency": other_currency,
115 "balances": values, 130 "balances": values,
116 "rates": rates, 131 "rates": rates,
117 "total": sum(amounts.values()).as_json()["value"] 132 "total": sum(amounts.values()).as_json()["value"]
118 }) 133 }
134
135 self.add_log(log.copy())
136 self.add_redis_status(log)
119 137
120 def log_dispatch(self, amount, amounts, liquidity, repartition): 138 def log_dispatch(self, amount, amounts, liquidity, repartition):
121 self.add_log({ 139 self.add_log({