Rework active order validation to only a subset of status

This commit is contained in:
Reckless_Satoshi 2022-01-17 15:22:44 -08:00
parent 28d18a4842
commit ae3a8cc0f5
No known key found for this signature in database
GPG Key ID: 9C4585B561315571

View File

@ -31,17 +31,25 @@ FIAT_EXCHANGE_DURATION = int(config('FIAT_EXCHANGE_DURATION'))
class Logics():
def validate_already_maker_or_taker(user):
'''Checks if the user is already partipant of an order'''
queryset = Order.objects.filter(maker=user)
'''Validates if a use is already not part of an active order'''
active_order_status = [Order.Status.WFB, Order.Status.PUB, Order.Status.TAK,
Order.Status.WF2, Order.Status.WFE, Order.Status.WFI,
Order.Status.CHA, Order.Status.FSE, Order.Status.DIS,
Order.Status.WFR]
'''Checks if the user is already partipant of an active order'''
queryset = Order.objects.filter(maker=user, status__in=active_order_status)
if queryset.exists():
return False, {'bad_request':'You are already maker of an order'}
queryset = Order.objects.filter(taker=user)
return False, {'bad_request':'You are already maker of an active order'}
queryset = Order.objects.filter(taker=user, status__in=active_order_status)
if queryset.exists():
return False, {'bad_request':'You are already taker of an order'}
return False, {'bad_request':'You are already taker of an active order'}
return True, None
def validate_order_size(order):
'''Checks if order is withing limits at t0'''
'''Validates if order is withing limits in satoshis at t0'''
if order.t0_satoshis > MAX_TRADE:
return False, {'bad_request': 'Your order is too big. It is worth '+'{:,}'.format(order.t0_satoshis)+' Sats now. But limit is '+'{:,}'.format(MAX_TRADE)+ ' Sats'}
if order.t0_satoshis < MIN_TRADE: