-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (31 loc) · 1016 Bytes
/
index.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
import Freecurrencyapi from "@everapi/freecurrencyapi-js";
import { getCurrencyList } from "./currencyList.js";
import { getHistoricalData } from "./HistoricalData.js";
import { getSpecifiedData } from "./SpecifiedHistoricalData.js";
import { getHistoricalRates } from "./OfflineHistoricalData.js";
const freecurrencyapi = new Freecurrencyapi(
"fca_live_867h8nithe8DERNQfEBTMSQqC6zAZsWXnA8EFUsZ"
);
const convertCurrency = async (fromCurrency, toCurrency, units) => {
try {
const res = await freecurrencyapi.latest({
base_currency: fromCurrency,
currencies: toCurrency,
});
const convertedCurrency = res.data[toCurrency];
const answer = convertedCurrency * units;
return answer;
} catch (error) {
throw new Error(
"Error occurred while converting currency: " + error.message
);
}
};
export {
convertCurrency,
getCurrencyList,
getHistoricalData,
getSpecifiedData,
getHistoricalRates,
};
//Usage: node <fileName> <from_currency> <to_currency> <units>