-
Notifications
You must be signed in to change notification settings - Fork 0
/
bank.js
30 lines (24 loc) · 784 Bytes
/
bank.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
async function bank(ccy, bankName) {
const url = "https://wx.sunrate.com/api/price/getAllBankForex"
try {
const response = await fetch(url, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
for (let i = 0; i < data.result.data.bank[ccy].length; i++) {
if (data.result.data.bank[ccy][i].bank === bankName) {
return parseFloat(data.result.data.bank[ccy][i].xh_sell_price)/100
}
}
} catch (error) {
console.error("Error fetching data: ", error);
}
}
async function main () {
const forex = await bank('USD','icbc')
console.log(forex)
}
main()