-
Notifications
You must be signed in to change notification settings - Fork 0
/
p2p.js
62 lines (53 loc) · 1.61 KB
/
p2p.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
async function bnP2P() {
const url = "https://p2p.binance.com/bapi/c2c/v2/friendly/c2c/adv/search";
const payload = {
proMerchantAds: false,
page: 1,
rows: 10,
PayTypes: ["BANK"],
asset: "USDT",
fiat: "CNY",
tradeType: "BUY",
};
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data
} catch (error) {
console.error("Error fetching data: ", error);
}
}
async function okxP2P() {
const timestamp = Date.now();
const url = `https://www.okx.com/v3/c2c/tradingOrders/books?quoteCurrency=CNY&baseCurrency=USDT&side=sell&paymentMethod=bank&userType=all&showTrade=false&showFollow=false&showAlreadyTraded=false&isAbleFilter=false&receivingAds=false&t=${timestamp}`;
try {
const response = await fetch(url, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data
} catch (error) {
console.error("Error fetching data: ", error);
}
}
async function bestPrice() {
const bnData = await bnP2P();
const bnBest = parseFloat(bnData.data[0].adv.price)
const okxData = await okxP2P();
const bestOkx = parseFloat(okxData.data.sell[0].price)
console.log(bnBest, bestOkx)
return bnBest > bestOkx ? console.log(bestOkx) : console.log(bnBest);
}
bestPrice()