Spaces:
Running

andervier commited on
Commit
b340bd0
·
1 Parent(s): 3cfc37e

fix: return average of ads[3..5] directly as the final price

Browse files
Files changed (1) hide show
  1. main.py +1 -35
main.py CHANGED
@@ -237,41 +237,7 @@ async def fetch_p2p() -> dict:
237
  if not sample:
238
  return None
239
 
240
- avg_price = sum(sample) / len(sample)
241
- fiat_ref = avg_price * 20 # ~20 USDT en VES
242
-
243
- for item in ads:
244
- adv = item.get("adv", {})
245
- try:
246
- price = float(adv["price"])
247
- surplus = float(adv.get("surplusAmount", 0))
248
- min_fiat = float(adv.get("minSingleTransAmount", 0))
249
- max_fiat = float(adv.get("maxSingleTransAmount", float("inf")))
250
- if surplus > 0 and min_fiat <= fiat_ref <= max_fiat:
251
- return price
252
- except (KeyError, ValueError, TypeError):
253
- continue
254
-
255
- for item in ads[3:]:
256
- adv = item.get("adv", {})
257
- try:
258
- price = float(adv["price"])
259
- surplus = float(adv.get("surplusAmount", 0))
260
- min_fiat = float(adv.get("minSingleTransAmount", 0))
261
- if surplus > 0 and min_fiat <= fiat_ref:
262
- return price
263
- except (KeyError, ValueError, TypeError):
264
- continue
265
-
266
- # Último recurso: primer anuncio desde índice 1 con stock
267
- for item in ads[1:]:
268
- adv = item.get("adv", {})
269
- try:
270
- if float(adv.get("surplusAmount", 0)) > 0:
271
- return float(adv["price"])
272
- except (KeyError, ValueError, TypeError):
273
- continue
274
- return None
275
 
276
  p2p_buy = first_eligible_price(sell_ads_res.json().get("data", []))
277
  p2p_sell = first_eligible_price(buy_ads_res.json().get("data", []))
 
237
  if not sample:
238
  return None
239
 
240
+ return round(sum(sample) / len(sample), 2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
  p2p_buy = first_eligible_price(sell_ads_res.json().get("data", []))
243
  p2p_sell = first_eligible_price(buy_ads_res.json().get("data", []))