adding a fixed exchange rate for the dollar to the ruble/fixing server failures

This commit is contained in:
Vladless
2025-10-05 13:32:11 +03:00
parent d073e1a3bd
commit d127624121
2 changed files with 8 additions and 8 deletions
+2 -2
View File
@@ -107,10 +107,10 @@ async def renew_on_3xui(
continue continue
if SUPERNODE: if SUPERNODE:
unique_email = f"{email}_{server_name.lower()}" unique_email = f"{email}_{server_name.lower()}"
sub_id_val = email if update_links else None sub_id_val = email
else: else:
unique_email = email unique_email = email
sub_id_val = unique_email if update_links else None sub_id_val = unique_email
traffic_bytes = total_gb * 1024 * 1024 * 1024 if total_gb else 0 traffic_bytes = total_gb * 1024 * 1024 * 1024 if total_gb else 0
async def process_server(si, inbound, uniq, sub, name): async def process_server(si, inbound, uniq, sub, name):
+6 -6
View File
@@ -5,7 +5,7 @@ from typing import Optional, Tuple
import time import time
from decimal import ROUND_HALF_UP, Decimal from decimal import ROUND_HALF_UP, Decimal
import aiohttp import aiohttp
from config import MULTICURRENCY_ENABLE, FX_MARKUP from config import MULTICURRENCY_ENABLE, FX_MARKUP, RUB_TO_USD
CBR_URL = "https://www.cbr-xml-daily.ru/daily_json.js" CBR_URL = "https://www.cbr-xml-daily.ru/daily_json.js"
@@ -33,15 +33,15 @@ async def to_rub(amount: float | Decimal, base: str, *, session: aiohttp.ClientS
async def get_rub_rate(quote: str, *, session: aiohttp.ClientSession | None = None) -> Decimal: async def get_rub_rate(quote: str, *, session: aiohttp.ClientSession | None = None) -> Decimal:
"""
Возвращает курс 'QUOTE per RUB' (сколько единиц валюты QUOTE приходится на 1 рубль).
Пример: для USD при 100 RUB за 1 USD вернёт 0.01 USD/RUB.
Здесь же применяется наценка FX_MARKUP (если задана и валюта не RUB).
"""
code = quote.upper() code = quote.upper()
if code == "RUB": if code == "RUB":
return Decimal("1") return Decimal("1")
if code == "USD" and RUB_TO_USD not in (False, None, 0):
rate = _q(Decimal("1") / Decimal(str(RUB_TO_USD)))
cache[code] = (time.time(), rate)
return rate
now = time.time() now = time.time()
cached = cache.get(code) cached = cache.get(code)
if cached and now - cached[0] < CACHE_TTL: if cached and now - cached[0] < CACHE_TTL: