Created
February 18, 2023 16:58
-
-
Save waiyanwh/5e718261f42da3b7998b9d511fcee91e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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