1.0.6 • Published 3 years ago

@tbhaxor/fixer v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Node Fixer

Node Fixer is an unofficial API Client for Fixer. Fixer is a simple and lightweight API for current and historical foreign exchange (forex) rates.

To get an API, you need to subscribe to atlest $10 plan https://fixer.io/product

Features

  • Lightweight
  • Fast
  • Nodejs and Browser Integration
  • Typescript support
  • API Calls to
    • Available currency symbols
    • Currency conversion (both latest and historic)
    • Timeseries of past 365 days
    • Fluctuations in the rate change of past 365 days

Installation

Nodejs

# yarn
yarn add @tbhaxor/fixer

# Npm
npm i @tbhaxor/fixer

CDN

<script src="https://cdn.jsdelivr.net/gh/tbhaxor/node-fixer/dist/bundle/fixer.web.js"></script>

Usage

// es6
import Fixer from '@tbhaxor/fixer';

// commonjs
const { default: Fixer } = require('@tbhaxor/fixer');

const fixer = new Fixer('API KEY HERE');

(async () => {
  const conversion = await fixer.convert(1, 'USD', 'INR');
  console.log(conversion.result); // 72.46
})();

API

All the callable methods are listed here

Symbols

Return all available currencies

Usage

(async () => {
  await fixer.symbols();
})();

N/A

NameTypeDescription
symbolsobjectAll supported currencies with their respective three-letter currency codes and names.

Latest Rates

Real-time exchange rate data updated every 60 minutes, every 10 minutes or every 60 seconds.

Usage

(async () => {
  await fixer.symbols('USD', ['INR', 'RSD', 'JPY']);
})();
NameTypeDescription
basestring(Optional) Enter the three-letter currency code of your preferred base currency. (default: USD)
symbolsstring[](Optional) Enter a list of currency codes to limit output currencies. (default: [])
NameTypeDescription
timestampnumberExact date and time (UNIX time stamp) the given rates were collected.
basestringThree-letter currency code of the base currency used for this request.
symbolsobjectExchange rate data for the currencies you have requested.

Conversion

Retrieve information about how currencies fluctuate on a day-to-day basis.

Note: Maximum allowed timeframe is 365 days.

Usage

(async () => {
  await fixer.convert(1, 'USD', 'INR');
})();
NameTypeDescription
ammountnumberThe amount to be converted.
basestringThree-letter currency code of the currency you would like to convert from.
targetstring[]Three-letter currency code of the currency you would like to convert to.
datestring(Optional) Specify a date (format YYYY-MM-DD) to use historical rates for this conversion.
NameTypeDescription
queryobjectSource requested
query.fromstringThree-letter currency code of the currency converted from.
query.tostringThree-letter currency code of the currency converted to.
query.amountnumberAmount that is converted.
infoobjectMetadata
info.timestampnumberExact date and time (UNIX time stamp) the given exchange rare was collected
info.ratenumberExchange rate used for your conversion.
historicalbooleanReturns true if historical rates are used for this conversion.
resultnumberConverted money. Use this to charge users

Fluctuation

Retrieve information about how currencies fluctuate on a day-to-day basis.

Note: Maximum allowed timeframe is 365 days.

Usage

(async () => {
  await fixer.fluctuation('2019-12-02', '2020-01-02', 'USD', ['INR', 'JPY']);
})();
NameTypeDescription
startstringThe start date (format YYYY-MM-DD) of your preferred fluctuation timeframe.
endstringThe end date (format YYYY-MM-DD) of your preferred fluctuation timeframe.
basestringThree-letter currency code of your preferred base currency. (default: USD)
symbolsstring[]List of currency codes to limit output currencies. (default: [])
NameTypeDescription
fluctuationbooleanReturned true if a request to the fluctuation endpoint is made.
start_datebooleanThe start date of your time frame.
end_datebooleanThe end date of your time frame.
basestringThree-letter currency code of the base currency used for this request.
ratesobjectExchange rate data for the currencies you have requested.
rates.<SYMBOL>.start_ratenumberExchange collected on your start date.
rates.<SYMBOL>.end_ratenumberExchange collected on your end date.
rates.<SYMBOL>.changenumberChange (decimal number) of the given currency rate between your start and end date.
rates.<SYMBOL>.change_pctnumberPercentage change of the given currency rate between your start and end date.

Timeseries

Query the API for daily historical rates between two dates of your choice, with a maximum time frame of 365 days.

Usage

(async () => {
  await fixer.timeseries('2019-12-02', '2020-01-02', 'USD', ['INR', 'JPY']);
})();
NameTypeDescription
startstringThe start date (format YYYY-MM-DD) of your preferred fluctuation timeframe.
endstringThe end date (format YYYY-MM-DD) of your preferred fluctuation timeframe.
basestringThree-letter currency code of your preferred base currency. (default: USD)
symbolsstring[]List of currency codes to limit output currencies. (default: [])
NameTypeDescription
timeseriesbooleanReturned true if a request to the timeseries endpoint is made.
start_datebooleanThe start date of your time frame.
end_datebooleanThe end date of your time frame.
basestringThree-letter currency code of the base currency used for this request.
rates"object of object"Exchange rate data for the currencies you have requested.

Error Handling

The generic response contains success key of boolean type. If there is any error, you will get error field with success = false

Error schema

NameTypeDescription
codenumberNumeric error code
typestringType of error (for developers)
infostringHuman readable message (for end users)

Contribution

Feel free to contribute to this project. I have convered almost all the feature this service provides, I would be interesting to see what you can do with it

Possible scope of contribution

  1. Documentation
  2. Issues
  3. Performance
  4. Removing axios dependencies and using creating own http mini utility compatible with nodejs and browser

Licence

Node Fixer is licensed under MIT License

Contact the Author

Follow the links to reach me