debug: add /v1/p2p/debug endpoint to inspect raw Binance ads
Browse files
main.py
CHANGED
|
@@ -254,3 +254,39 @@ async def fetch_p2p_safe() -> dict:
|
|
| 254 |
@app.get("/v1/p2p", dependencies=[Depends(verify_app_check)])
|
| 255 |
async def p2p():
|
| 256 |
return await fetch_p2p()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
@app.get("/v1/p2p", dependencies=[Depends(verify_app_check)])
|
| 255 |
async def p2p():
|
| 256 |
return await fetch_p2p()
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
@app.get("/v1/p2p/debug")
|
| 260 |
+
async def p2p_debug():
|
| 261 |
+
"""Devuelve los primeros 5 anuncios crudos de cada direcci贸n para diagn贸stico."""
|
| 262 |
+
headers = {"User-Agent": "Mozilla/5.0", "Content-Type": "application/json"}
|
| 263 |
+
body_base = {
|
| 264 |
+
"fiat": "VES", "page": 1, "rows": 10, "asset": "USDT",
|
| 265 |
+
"countries": [], "proMerchantAds": False, "shieldMerchantAds": False,
|
| 266 |
+
"publisherType": None, "payTypes": [],
|
| 267 |
+
"classifies": ["mass", "profession"],
|
| 268 |
+
}
|
| 269 |
+
async with httpx.AsyncClient(timeout=10) as client:
|
| 270 |
+
buy_res, sell_res = await asyncio.gather(
|
| 271 |
+
client.post("https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search",
|
| 272 |
+
json={**body_base, "tradeType": "BUY"}, headers=headers),
|
| 273 |
+
client.post("https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search",
|
| 274 |
+
json={**body_base, "tradeType": "SELL"}, headers=headers),
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
def extract(ads):
|
| 278 |
+
return [
|
| 279 |
+
{
|
| 280 |
+
"price": item["adv"].get("price"),
|
| 281 |
+
"surplusAmount": item["adv"].get("surplusAmount"),
|
| 282 |
+
"minSingleTransAmount": item["adv"].get("minSingleTransAmount"),
|
| 283 |
+
"maxSingleTransAmount": item["adv"].get("maxSingleTransAmount"),
|
| 284 |
+
"publisherType": item["adv"].get("publisherType"),
|
| 285 |
+
}
|
| 286 |
+
for item in ads[:5]
|
| 287 |
+
]
|
| 288 |
+
|
| 289 |
+
return {
|
| 290 |
+
"buy_ads": extract(buy_res.json().get("data", [])),
|
| 291 |
+
"sell_ads": extract(sell_res.json().get("data", [])),
|
| 292 |
+
}
|