From d3b4d3ea21ba854e23f4a42fe9759b19001722a1 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 3 May 2022 08:48:42 +0100 Subject: [PATCH] Do not clean up other platforms' trades --- handler/transactions.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/handler/transactions.py b/handler/transactions.py index bf90605..dabb4df 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -677,6 +677,11 @@ class Transactions(util.Base): return False return tx_data + def get_subclass(self, reference): + obj = r.hget(f"trade.{reference}", "subclass") + subclass = util.convert(obj) + return subclass + def del_ref(self, reference): """ Delete a given reference from the Redis database. @@ -687,7 +692,7 @@ class Transactions(util.Base): r.delete(f"trade.{reference}") r.delete(f"trade.{tx}.reference") - def cleanup(self, references): + def cleanup(self, subclass, references): """ Reconcile the internal reference database with a given list of references. Delete all internal references not present in the list and clean up artifacts. @@ -696,9 +701,10 @@ class Transactions(util.Base): """ for tx, reference in self.get_ref_map().items(): if reference not in references: - self.log.info(f"Archiving trade reference: {reference} / TX: {tx}") - r.rename(f"trade.{tx}.reference", f"archive.trade.{tx}.reference") - r.rename(f"trade.{reference}", f"archive.trade.{reference}") + if self.get_subclass(reference) == subclass: + self.log.info(f"Archiving trade reference: {reference} / TX: {tx}") + r.rename(f"trade.{tx}.reference", f"archive.trade.{tx}.reference") + r.rename(f"trade.{reference}", f"archive.trade.{reference}") def tx_to_ref(self, tx): """ @@ -712,6 +718,7 @@ class Transactions(util.Base): for reference in refs: ref_data = util.convert(r.hgetall(f"trade.{reference}")) if not ref_data: + print("NOT REF DATA") continue if ref_data["id"] == tx: return reference