featL min 5000 rub

This commit is contained in:
2026-05-22 01:10:52 +03:00
parent dc213cb9d9
commit 565816e710
2 changed files with 16 additions and 18 deletions

View File

@@ -6,7 +6,7 @@ from src.application.contracts import ICache, ILogger
from src.application.domain.exceptions import OrderTotalOutOfRangeException, ServiceUnavailableException
_MIN_USDT_AMOUNT: Decimal = Decimal('1')
_MIN_TOTAL_RUB: Decimal = Decimal('5000')
_MAX_TOTAL_RUB: Decimal = Decimal('600000')
@@ -105,8 +105,8 @@ class PaymentQuoteService:
)
async def get_quote(self, usdt_amount: Decimal) -> PaymentQuote:
if usdt_amount < _MIN_USDT_AMOUNT:
async def get_reference_quote(self, usdt_amount: Decimal) -> PaymentQuote:
if usdt_amount <= Decimal('0'):
raise OrderTotalOutOfRangeException(
message='Order total is below minimum allowed amount',
)
@@ -120,8 +120,17 @@ class PaymentQuoteService:
return quote
async def get_quote(self, usdt_amount: Decimal) -> PaymentQuote:
quote = await self.get_reference_quote(usdt_amount)
if quote.total_price < _MIN_TOTAL_RUB:
raise OrderTotalOutOfRangeException(
message='Order total is below minimum allowed amount',
)
return quote
async def get_quote_from_total_rub(self, total_rub: Decimal) -> PaymentQuote:
if total_rub <= Decimal('0'):
if total_rub < _MIN_TOTAL_RUB:
raise OrderTotalOutOfRangeException(
message='Order total is below minimum allowed amount',
)
@@ -133,17 +142,6 @@ class PaymentQuoteService:
usdt_exchange_rate, gas_fee = await self._load_prices()
if total_rub <= gas_fee:
raise OrderTotalOutOfRangeException(
message='Order total is below minimum allowed amount',
)
min_quote = self._compose_quote(_MIN_USDT_AMOUNT, usdt_exchange_rate, gas_fee)
if min_quote is None or min_quote.total_price > total_rub:
raise OrderTotalOutOfRangeException(
message='Order total is below minimum allowed amount',
)
u_budget = ((total_rub - gas_fee) / usdt_exchange_rate).quantize(Decimal('0.01'), rounding=ROUND_DOWN)
u_cap = ((_MAX_TOTAL_RUB - gas_fee) / (usdt_exchange_rate * Decimal('1.04'))).quantize(
Decimal('0.01'),
@@ -151,12 +149,12 @@ class PaymentQuoteService:
)
u_upper = min(u_budget, u_cap)
n_hi = int((u_upper * 100).to_integral_value(rounding=ROUND_DOWN))
if n_hi < 100:
if n_hi < 1:
raise OrderTotalOutOfRangeException(
message='Order total is below minimum allowed amount',
)
n_lo = 100
n_lo = 1
best_cent: int | None = None
while n_lo <= n_hi:
mid = (n_lo + n_hi) // 2