-1

Can somebody help me? I have a telegram-bot for get p2p offers from binance. It worked good long time. But now I have a problem (2 days). I couldn't get offers for currency RUB. Output data is empty list. If I insert cookies from browser in headers, it works good. But I think this is not a good solution. Maybe I can authenticate and send request with auth data? Binance have API, but it not work with p2p

import requests as rq
import json
from pprint import pprint
from binance.spot import Spot
from binance.client import Client
​
client = Spot(api_key=BINANCE_API_KEY, api_secret=BINANCE_SECRET_KEY)
client2 = Client(BINANCE_API_KEY, BINANCE_SECRET_KEY)
​
​
def get_binance_data(asset='USDT', fiat='RUB', pay_types=('PostBankNew', ), trade_type='BUY', amount=1000, page=1):
    data = {
        "asset": asset,
        "fiat": fiat,
        "countries": [],
        "merchantCheck": None,
        "page": page,
        "payTypes": list(pay_types),
        "proMerchantAds": False,
        "publisherType": "merchant",
        "rows": 20,
        "shieldMerchantAds": False,
        "tradeType": trade_type,
        "transAmount": amount,
    }
    headers = {...}
    response = rq.post('https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search', json=data, headers=headers)
    response2 = client.session.post('https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search', json=data)
    pprint(response2.text)
    pprint(response.text)
    return json.loads(response.text)['data']

response with cookie and csrf in headers return correct result with offers

response without cookie and csrf in headers return empty list

response2 return empty list

  • when scraping like this, there is no other option as running separate script with puppeteer or playwright which will open the p2p page with fiat pair you need and save the cookies to json file. then use these cookies in you request until it start returning empty list, then start puppeteer to refresh cookies again. If you send requests not very often - you can take the data you need right from puppeteer "page.on('response', ..." listener, but if you poll binance often, it won't be handy – Michael Perelman Sep 01 '23 at 16:55

0 Answers0