diff --git a/core/clients/aggregator.py b/core/clients/aggregator.py index c851c80..8983540 100644 --- a/core/clients/aggregator.py +++ b/core/clients/aggregator.py @@ -59,9 +59,9 @@ class AggregatorClient(ABC): # for transaction_id in transaction_ids: if not transaction_ids: return - db.r.sadd(new_key_name, *transaction_ids) + await db.r.sadd(new_key_name, *transaction_ids) - difference = list(db.r.sdiff(new_key_name, old_key_name)) + difference = list(await db.r.sdiff(new_key_name, old_key_name)) difference = db.convert(difference) @@ -70,7 +70,7 @@ class AggregatorClient(ABC): ] # Rename the new key to the old key so we can run the diff again - db.r.rename(new_key_name, old_key_name) + await db.r.rename(new_key_name, old_key_name) for transaction in new_transactions: transaction["subclass"] = self.name # self.tx.transaction(transaction) diff --git a/core/models.py b/core/models.py index 26fa357..5e2ddc8 100644 --- a/core/models.py +++ b/core/models.py @@ -259,6 +259,57 @@ class Ad(models.Model): return cls.objects.filter(id=ad_id, user=user, enabled=True).first() +class Transaction(models.Model): + """ + A transaction on an aggregator. + """ + + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + aggregator = models.ForeignKey(Aggregator, on_delete=models.CASCADE) + account_id = models.CharField(max_length=255) + + ts_added = ... + + recipient = models.CharField(max_length=255, null=True, blank=True) + sender = models.CharField(max_length=255, null=True, blank=True) + + amount = models.FloatField() + currency = models.CharField(max_length=16) + + note = models.CharField(max_length=255, null=True, blank=True) + + reconciled = models.BooleanField(default=False) + + +class Trade(models.Model): + """ + A trade on a Platform. + """ + + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + platform = models.ForeignKey(Platform, on_delete=models.CASCADE) + + contact_id = models.CharField(max_length=255) + reference = models.CharField(max_length=255) + buyer = models.CharField(max_length=255) + seller = models.CharField(max_length=255) + amount_fiat = models.FloatField() + currency = models.CharField(max_length=16) + amount_crypto = models.FloatField() + coin = models.CharField(max_length=16) + provider = models.CharField(max_length=255) + type = models.CharField(max_length=255) + ad_id = models.CharField(max_length=255) + + status = models.CharField(max_length=255) + + linked = models.ManyToManyField(Transaction) + reconciled = models.BooleanField(default=False) + + released = models.BooleanField(default=False) + release_response = models.JSONField(default=dict) + + assets = { "XMR": "Monero", "BTC": "Bitcoin",