fix: skip first 3 ads, average ads 4-6 as price reference for p2p filter
Browse files
main.py
CHANGED
|
@@ -180,20 +180,16 @@ async def fetch_p2p() -> dict:
|
|
| 180 |
if not ads:
|
| 181 |
return None
|
| 182 |
|
| 183 |
-
# Paso 1: promedio de ads[
|
| 184 |
sample = []
|
| 185 |
-
for item in ads[
|
| 186 |
try:
|
| 187 |
sample.append(float(item["adv"]["price"]))
|
| 188 |
except (KeyError, ValueError, TypeError):
|
| 189 |
pass
|
| 190 |
|
| 191 |
if not sample:
|
| 192 |
-
|
| 193 |
-
try:
|
| 194 |
-
sample = [float(ads[0]["adv"]["price"])]
|
| 195 |
-
except (KeyError, ValueError, TypeError):
|
| 196 |
-
return None
|
| 197 |
|
| 198 |
avg_price = sum(sample) / len(sample)
|
| 199 |
fiat_ref = avg_price * 20 # ~20 USDT en VES
|
|
@@ -211,8 +207,8 @@ async def fetch_p2p() -> dict:
|
|
| 211 |
except (KeyError, ValueError, TypeError):
|
| 212 |
continue
|
| 213 |
|
| 214 |
-
# Fallback: primer anuncio desde índice
|
| 215 |
-
for item in ads[
|
| 216 |
adv = item.get("adv", {})
|
| 217 |
try:
|
| 218 |
price = float(adv["price"])
|
|
|
|
| 180 |
if not ads:
|
| 181 |
return None
|
| 182 |
|
| 183 |
+
# Paso 1: promedio de ads[3..5] (saltamos los primeros 3)
|
| 184 |
sample = []
|
| 185 |
+
for item in ads[3:6]:
|
| 186 |
try:
|
| 187 |
sample.append(float(item["adv"]["price"]))
|
| 188 |
except (KeyError, ValueError, TypeError):
|
| 189 |
pass
|
| 190 |
|
| 191 |
if not sample:
|
| 192 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
avg_price = sum(sample) / len(sample)
|
| 195 |
fiat_ref = avg_price * 20 # ~20 USDT en VES
|
|
|
|
| 207 |
except (KeyError, ValueError, TypeError):
|
| 208 |
continue
|
| 209 |
|
| 210 |
+
# Fallback: primer anuncio desde índice 3 con min <= fiat_ref
|
| 211 |
+
for item in ads[3:]:
|
| 212 |
adv = item.get("adv", {})
|
| 213 |
try:
|
| 214 |
price = float(adv["price"])
|