Skip to content

Instantly share code, notes, and snippets.

@waiyanwh
Created February 18, 2023 16:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waiyanwh/5e718261f42da3b7998b9d511fcee91e to your computer and use it in GitHub Desktop.
Save waiyanwh/5e718261f42da3b7998b9d511fcee91e to your computer and use it in GitHub Desktop.
const https = require("https");
function fetchP2PData(page = 1, fiat = "MMK", tradeType = "BUY", asset = "USDT", payTypes = []) {
return new Promise((resolve, reject) => {
const baseObj = {
page,
rows: 3,
publisherType: null,
asset,
tradeType,
fiat,
payTypes,
};
const stringData = JSON.stringify(baseObj);
const options = {
hostname: "p2p.binance.com",
port: 443,
path: "/bapi/c2c/v2/friendly/c2c/adv/search",
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": stringData.length,
},
};
const req = https.request(options, (res) => {
let output = "";
res.on("data", (d) => {
output += d;
});
res.on("end", () => {
try {
const jsonOuput = JSON.parse(output);
resolve(jsonOuput);
} catch (e) {
reject(e);
}
});
});
req.on("error", (error) => {
reject(error);
});
req.write(stringData);
req.end();
});
}
module.exports = fetchP2PData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment