fix: p2p price uses first ad as ref (price*20), searches from 2nd ad where min<=fiat_ref
Browse files
main.py
CHANGED
|
@@ -171,37 +171,34 @@ async def fetch_p2p() -> dict:
|
|
| 171 |
|
| 172 |
def first_eligible_price(ads: list) -> float | None:
|
| 173 |
"""
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
Fallback: primer anuncio con surplus > 0.
|
| 179 |
"""
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
|
| 189 |
if ref_price is not None:
|
| 190 |
-
fiat_ref =
|
| 191 |
-
|
| 192 |
-
for item in ads:
|
| 193 |
adv = item.get("adv", {})
|
| 194 |
try:
|
| 195 |
-
price
|
| 196 |
surplus = float(adv.get("surplusAmount", 0))
|
| 197 |
min_fiat = float(adv.get("minSingleTransAmount", 0))
|
| 198 |
-
|
| 199 |
-
if surplus > 0 and min_fiat <= fiat_ref <= max_fiat:
|
| 200 |
return price
|
| 201 |
except (KeyError, ValueError, TypeError):
|
| 202 |
continue
|
| 203 |
|
| 204 |
-
# Fallback:
|
| 205 |
for item in ads[1:]:
|
| 206 |
adv = item.get("adv", {})
|
| 207 |
try:
|
|
|
|
| 171 |
|
| 172 |
def first_eligible_price(ads: list) -> float | None:
|
| 173 |
"""
|
| 174 |
+
1. Usa el precio del 1er anuncio como referencia → fiat_ref = precio * 20
|
| 175 |
+
2. Desde el 2do anuncio en adelante, devuelve el primero cuyo
|
| 176 |
+
minSingleTransAmount <= fiat_ref (descarta anuncios con mínimos altísimos).
|
| 177 |
+
Fallback: 2do anuncio con surplus > 0.
|
|
|
|
| 178 |
"""
|
| 179 |
+
if not ads:
|
| 180 |
+
return None
|
| 181 |
+
|
| 182 |
+
# Referencia: primer anuncio
|
| 183 |
+
try:
|
| 184 |
+
ref_price = float(ads[0]["adv"]["price"])
|
| 185 |
+
except (KeyError, ValueError, TypeError):
|
| 186 |
+
ref_price = None
|
| 187 |
|
| 188 |
if ref_price is not None:
|
| 189 |
+
fiat_ref = ref_price * 20 # ~20 USDT en VES como umbral
|
| 190 |
+
for item in ads[1:]:
|
|
|
|
| 191 |
adv = item.get("adv", {})
|
| 192 |
try:
|
| 193 |
+
price = float(adv["price"])
|
| 194 |
surplus = float(adv.get("surplusAmount", 0))
|
| 195 |
min_fiat = float(adv.get("minSingleTransAmount", 0))
|
| 196 |
+
if surplus > 0 and min_fiat <= fiat_ref:
|
|
|
|
| 197 |
return price
|
| 198 |
except (KeyError, ValueError, TypeError):
|
| 199 |
continue
|
| 200 |
|
| 201 |
+
# Fallback: 2do anuncio con stock
|
| 202 |
for item in ads[1:]:
|
| 203 |
adv = item.get("adv", {})
|
| 204 |
try:
|