11

I am trying to access the data on this Binance website. It is the P2P: https://p2p.binance.com/en/trade/buy/USDT.

For BUY I am using this in python3 (I am getting the data correctly for this section):

import requests


headers = {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
    "Cache-Control": "no-cache",
    "Connection": "keep-alive",
    "Content-Length": "123",
    "content-type": "application/json",
    "Host": "p2p.binance.com",
    "Origin": "https://p2p.binance.com",
    "Pragma": "no-cache",
    "TE": "Trailers",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0"
}

data = {
  "asset": "USDT",
  "fiat": "ARS",
  "merchantCheck": False,
  "page": 1,
  "payTypes": [],
  "publisherType": None,
  "rows": 50,
  "tradeType": "BUY"
}


r = requests.post('https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search', headers=headers, json=data)
print(r.text)

But then when I want to access this part of the page: https://p2p.binance.com/en/trade/sell/USDT (to SELL), I can't do it. Because when I change in the data the following: "tradeType": "SELL", it still brings me the same values of the BUY. It never brings me the SELL data.

And I am not finding out why yet.

Marcos
  • 159
  • 1
  • 1
  • 8
  • I'm getting `{"code":"083996","message":"Please check the input info","messageDetail":{"title":null,"type":null,"icon":null,"action":null,"linkTitle":null,"linkUrl":null},"data":null,"success":false}` when running your original BUY code. – Bernardo Jun 15 '21 at 23:14

5 Answers5

9

Instead of sending requests to the website itself you can send a request to the source itself. If you check your console while the website loads results you will notice it sends a request to https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search which returns an array of trade details. I believe this is what you need.

6

Expanding on the accepted answer:

https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search

POST fields

{
    "asset": "USDT",
    "fiat": "NGN",
    "merchantCheck": true,
    "page": 1,
    "payTypes": ["BANK"],
    "publisherType": null,
    "rows": 20,
    "tradeType": "SELL",
    "transAmount":  "5000"
}

asset: Currently available asset USDT, BTC, BNB, BUSD, ETH, DAI.

fiat: Its long, visit sanchezmarcos.

merchantCheck: Well i don't know its use, but value is null, true, false.

page: The endpoint is paginated.

payTypes: An array of payment types example BANK, GoMoney, CashDeposit etc.

payTypes depend on fiat used so you might not see some of these but there's a lot of payment types.

publisherType: I'm only aware of merchant.

row: Amount of rows from 1 - 20.

tradeType: BUY or SELL.

transAmount: Filter merchant by amount.

Note: The api is for binance internal operation which means it can change any time.

As per the comment, it seems the wrong specification of some values can cause unknown errors.

Frank nike
  • 330
  • 5
  • 12
  • It returns Dear User, this payment method is unsupported on Binance P2P. You can still buy and sell cryptocurrency on our official partner's platform https://www.pexpay.com/en – VityaSchel Apr 20 '23 at 10:01
  • 1
    @VityaSchel it turns out it only returns this error when requesting "RUB" as value for "fiat" key *upd*: reverse-engineering api of p2p I found that you just have to find correct `payTypes`, for example `TinkoffNew` – VityaSchel Apr 20 '23 at 10:03
  • It's good to know you resolved it. – Frank nike Apr 21 '23 at 02:10
0

I did check the result of the api call and confirm the data is correct except tradeType, you did nothing wrong

Tiana987642
  • 696
  • 2
  • 10
  • 28
0

You need use it:

client.get_c2c_trade_history() and go to ['data'] Next step is work like json or dateframe, the column that you need have the header 'tradeType'

0

the price api is returning is different from what the app is showing.

Ankit
  • 609
  • 2
  • 10
  • 26