self.print_logs = []
self.logs = []
+ self.redis_status = []
self.no_http_dup = no_http_dup
self.last_http = None
self.logs.append(hash_)
return hash_
+ def add_redis_status(self, hash_):
+ self.redis_status.append(hash_)
+ return hash_
+
@staticmethod
def default_json_serial(obj):
if isinstance(obj, (datetime.datetime, datetime.date)):
json.dumps(log, default=self.default_json_serial, indent=" ")
)
+ def to_json_redis(self):
+ for log in (x.copy() for x in self.redis_status):
+ yield (
+ log.pop("type"),
+ json.dumps(log, default=self.default_json_serial)
+ )
+
def set_verbose(self, verbose_print):
self.verbose_print = verbose_print
for currency, balance in self.market.balances.all.items():
self.print_log("\t{}".format(balance))
- self.add_log({
- "type": "balance",
- "tag": tag,
- "balances": self.market.balances.as_json()
- })
+ log = {
+ "type": "balance",
+ "tag": tag,
+ "balances": self.market.balances.as_json()
+ }
+
+ self.add_log(log.copy())
+ self.add_redis_status(log)
def log_tickers(self, amounts, other_currency,
compute_value, type):
for currency, amount in amounts.items():
values[currency] = amount.as_json()["value"]
rates[currency] = amount.rate
- self.add_log({
- "type": "tickers",
- "compute_value": compute_value,
- "balance_type": type,
- "currency": other_currency,
- "balances": values,
- "rates": rates,
- "total": sum(amounts.values()).as_json()["value"]
- })
+ log = {
+ "type": "tickers",
+ "compute_value": compute_value,
+ "balance_type": type,
+ "currency": other_currency,
+ "balances": values,
+ "rates": rates,
+ "total": sum(amounts.values()).as_json()["value"]
+ }
+
+ self.add_log(log.copy())
+ self.add_redis_status(log)
def log_dispatch(self, amount, amounts, liquidity, repartition):
self.add_log({