Do not clean up other platforms' trades

This commit is contained in:
Mark Veidemanis 2022-05-03 08:48:42 +01:00
parent 6bf3daee4c
commit d3b4d3ea21
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 11 additions and 4 deletions

View File

@ -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