class Order(TimestampedModel): class Meta: verbose_name = 'Exch Buying Order' verbose_name_plural = 'Exch Buying Orders' user = models.ForeignKey(ExchangeUser, related_name='user_orders', on_delete=models.PROTECT) user_info = models.TextField(null=True) amount = model_fields.CryptoAmountField() currency = model_fields.CurrencyField() fiat_amount = model_fields.FiatAmountField() fiat_currency = model_fields.FiatCurrencyField() fiat_local_amount = model_fields.FiatAmountField() fiat_local_currency = model_fields.FiatCurrencyField() raw_fiat_amount = model_fields.FiatAmountField() price = model_fields.FiatAmountField() status = models.CharField(max_length=20, choices=ORDER_STATUS, default=ORDER_STATUS.pending) order_type = models.CharField(max_length=20, choices=ORDER_TYPE) order_user_payment_type = models.CharField(max_length=20, choices=ORDER_USER_PAYMENT_TYPE, null=True, blank=True) direction = model_fields.DirectionField() duration = models.IntegerField(null=True) fee = model_fields.FiatAmountField() address = model_fields.CryptoHashField() tx_hash = model_fields.CryptoHashField(null=True, blank=True) provider_data = models.TextField(null=True) receipt_url = models.CharField(max_length=500, null=True, blank=True) ref_code = models.CharField(max_length=10) reviewed = models.BooleanField(default=False) first_purchase = models.BooleanField(default=False) def __str__(self): return 'Order #{} for {}ing {:.6f} {}'.format(self.id, self.direction, self.amount, self.currency) def format_amount(self): return '{:.6f}'.format(self.amount) format_amount.short_description = 'Amount' def _destroy_order(self, status): self.status = status self.save(update_fields=['status', 'updated_at'])
class PromotionRule(TimestampedModel): class Meta: verbose_name = 'Promotion Rule' verbose_name_plural = 'Promotion Rules' country = model_fields.CountryField() currency = model_fields.FiatCurrencyField() active = models.BooleanField(default=True) first_click_count = models.IntegerField(default=0) first_click_amount = models.IntegerField(default=0) first_click_days = models.IntegerField(default=0) first_click_bonus = model_fields.FiatAmountField() first_referral_count = models.IntegerField(default=0) first_referral_amount = model_fields.FiatAmountField(default=0) first_referral_referrer_bonus = model_fields.FiatAmountField(default=0) first_referral_referee_bonus = model_fields.FiatAmountField(default=0) referrer_percentage = models.DecimalField(max_digits=7, decimal_places=4, default=0) referrer_next_duration = models.IntegerField(default=0) referrer_percentage_2 = models.DecimalField(max_digits=7, decimal_places=4, default=0) referee_percentage = models.DecimalField(max_digits=7, decimal_places=4, default=0) referee_next_duration = models.IntegerField(default=0) referee_percentage_2 = models.DecimalField(max_digits=7, decimal_places=4, default=0)
class Payment(TimestampedModel): order = models.ForeignKey(Order, related_name='order_payments', on_delete=models.PROTECT) fiat_amount = model_fields.FiatAmountField() fiat_currency = model_fields.FiatCurrencyField() overspent = model_fields.FiatAmountField() status = models.CharField(max_length=20, choices=PAYMENT_STATUS)
class PromotionUser(TimestampedModel): user = models.OneToOneField(ExchangeUser, related_name='user_promotion', on_delete=models.PROTECT) first_click_count = models.IntegerField(default=0) first_click_amount = model_fields.FiatAmountField(default=0) first_click_expired = models.DateTimeField(null=True) referral_count = models.IntegerField(default=0) referral_amount = model_fields.FiatAmountField(default=0) currency = model_fields.FiatCurrencyField()
class CountryDefaultConfig(models.Model): class Meta: verbose_name = 'Country Default Config' verbose_name_plural = 'Country Default Configs' country = model_fields.CountryField(primary_key=True) country_name = models.CharField(max_length=50, blank=True) phone_country_code = models.CharField(max_length=5, blank=True) language = model_fields.LanguageField() currency = model_fields.FiatCurrencyField() active = models.BooleanField(default=True)
class CountryCurrency(models.Model): class Meta: unique_together = ('country', 'currency') verbose_name = 'Country Currency' verbose_name_plural = 'Country Currencies' country = model_fields.CountryField() currency = model_fields.FiatCurrencyField() active = models.BooleanField(default=True) def __str__(self): return '%s - %s' % (self.country, self.currency)
class Bank(models.Model): class Meta: unique_together = ('country', 'currency') country = model_fields.CountryField() currency = model_fields.FiatCurrencyField() account_name = models.CharField(max_length=255, blank=True) account_number = models.CharField(max_length=255, blank=True) bank_name = models.CharField(max_length=255, blank=True) bank_id = models.CharField(max_length=255, blank=True) active = models.BooleanField(default=True) def __str__(self): return '%s - %s (%s)' % (self.bank_name, self.country, self.currency)
class UserLimit(TimestampedModel): class Meta: unique_together = ('user', 'direction') user = models.ForeignKey(ExchangeUser, related_name='user_limit', on_delete=models.CASCADE) direction = model_fields.DirectionField() limit = model_fields.FiatAmountField() usage = model_fields.FiatAmountField() fiat_currency = model_fields.FiatCurrencyField() def __str__(self): return '%s - %s' % (DIRECTION[self.direction] if self.direction != DIRECTION_ALL else 'All', self.fiat_currency)
class PromotionOrder(TimestampedModel): class Meta: verbose_name = 'Promotion Transaction' verbose_name_plural = 'Promotion Transactions' order = models.ForeignKey(Order, related_name='order_promotions', on_delete=models.PROTECT) user = models.ForeignKey(ExchangeUser, related_name='user_order_promotions', null=True, on_delete=models.PROTECT) amount = model_fields.FiatAmountField() currency = model_fields.FiatCurrencyField() status = models.CharField(max_length=20, choices=REFERRAL_STATUS, default=REFERRAL_STATUS.pending) referrer = models.BooleanField(default=True) note = models.CharField(max_length=200, null=True, blank=True)
class PaymentDetail(TimestampedModel): payment = models.ForeignKey(Payment, related_name='payment_details', on_delete=models.PROTECT) fiat_amount = model_fields.FiatAmountField() fiat_currency = model_fields.FiatCurrencyField()