-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
735 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 5.1.4 on 2025-02-24 13:10 | ||
|
||
import django.core.validators | ||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0050_alter_order_status'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='TakeOrder', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('amount', models.DecimalField(blank=True, decimal_places=8, max_digits=18, null=True)), | ||
('expires_at', models.DateTimeField()), | ||
('last_satoshis', models.PositiveBigIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(10000000)])), | ||
('last_satoshis_time', models.DateTimeField(blank=True, default=None, null=True)), | ||
('order', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='order', to='api.order')), | ||
('taker', models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='pretaker', to=settings.AUTH_USER_MODEL)), | ||
('taker_bond', models.OneToOneField(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, to='api.lnpayment')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from django.core.validators import MaxValueValidator, MinValueValidator | ||
from django.contrib.auth.models import User | ||
from django.db import models | ||
from django.conf import settings | ||
from django.utils import timezone | ||
|
||
|
||
class TakeOrder(models.Model): | ||
amount = models.DecimalField(max_digits=18, decimal_places=8, null=True, blank=True) | ||
order = models.ForeignKey( | ||
"api.Order", | ||
related_name="order", | ||
on_delete=models.CASCADE, | ||
null=False, | ||
default=None, | ||
blank=False, | ||
) | ||
taker = models.ForeignKey( | ||
User, | ||
related_name="pretaker", | ||
on_delete=models.CASCADE, | ||
null=False, | ||
default=None, | ||
blank=False, | ||
) | ||
expires_at = models.DateTimeField() | ||
taker_bond = models.OneToOneField( | ||
"api.LNPayment", | ||
related_name="take_order", | ||
on_delete=models.SET_NULL, | ||
null=True, | ||
default=None, | ||
blank=True, | ||
) | ||
last_satoshis = models.PositiveBigIntegerField( | ||
null=True, | ||
default=None, | ||
validators=[MinValueValidator(0), MaxValueValidator(settings.MAX_TRADE * 2)], | ||
blank=True, | ||
) | ||
# timestamp of last_satoshis | ||
last_satoshis_time = models.DateTimeField(null=True, default=None, blank=True) | ||
|
||
def cancel(self, cls): | ||
if self.expires_at > timezone.now(): | ||
self.expires_at = timezone.now() | ||
self.save(update_fields=["expires_at"]) | ||
cls.cancel_bond(self.taker_bond) | ||
|
||
def __str__(self): | ||
return f"Order {self.order.id} taken by Robot({self.taker.robot.id},{self.taker.username}) for {self.amount} fiat units" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.