-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 867b32d
Showing
6 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.npmrc | ||
node_modules/ | ||
package-lock.json |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 ForexRateAPI | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# ForexRateAPI | ||
|
||
forexrateapi is the official Node.js wrapper for ForexRateAPI.com. This allows you to quickly integrate our foreign exchange rate API and currency conversion API into your application. Check https://forexrateapi.com documentation for more information. | ||
|
||
|
||
|
||
## Installation | ||
|
||
#### NPM | ||
|
||
``` | ||
$ npm i forexrateapi | ||
``` | ||
--- | ||
## Usage | ||
|
||
```js | ||
const api = require('forexrateapi'); | ||
|
||
api.setAPIKey('SET_YOUR_API_KEY_HERE'); | ||
await api.fetchLive('USD', ['AUD', 'CAD', 'GBP', 'JPY']); | ||
``` | ||
--- | ||
## Documentation | ||
|
||
#### setAPIKey(apiKey) | ||
|
||
- `apiKey` <[string]> API Key | ||
|
||
In order to use this library, you must first call this function with an API key. | ||
|
||
```js | ||
api.setAPIKey('SET_YOUR_API_KEY_HERE'); | ||
``` | ||
--- | ||
#### fetchSymbols() | ||
```js | ||
await api.fetchSymbols(); | ||
``` | ||
|
||
[Link](https://forexrateapi.com/documentation#api_symbol) | ||
|
||
--- | ||
#### fetchLive(base, currencies) | ||
|
||
- `base` <[string]> Optional. Pass in a base currency, defaults to USD. | ||
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for. | ||
|
||
```js | ||
await api.fetchLive('USD', ['AUD', 'CAD', 'GBP', 'JPY']); | ||
``` | ||
|
||
[Link](https://forexrateapi.com/documentation#api_realtime) | ||
|
||
--- | ||
#### fetchHistorical(date, base, currencies) | ||
|
||
- `date` <[string]> Required. Pass in a string with format `YYYY-MM-DD` | ||
- `base` <[string]> Optional. Pass in a base currency, defaults to USD. | ||
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for. | ||
|
||
```js | ||
await api.fetchHistorical('2021-04-05', 'USD', ['AUD', 'CAD', 'GBP', 'JPY']); | ||
``` | ||
|
||
[Link](https://forexrateapi.com/documentation#api_historical) | ||
|
||
--- | ||
#### convert(from, to, amount, date) | ||
|
||
- `from` <[string]> Optional. Pass in a base currency, defaults to USD. | ||
- `to` <[string]> Required. Specify currency you would like to convert to. | ||
- `amount` <[number]> Required. The amount to convert. | ||
- `date` <[string]> Optional. Specify date to use historical midpoint value for conversion with format `YYYY-MM-DD`. Otherwise, it will use live exchange rate date if value not passed in. | ||
|
||
```js | ||
await api.convert('USD', 'EUR', 100, '2021-04-05'); | ||
``` | ||
|
||
[Link](https://forexrateapi.com/documentation#api_convert) | ||
|
||
--- | ||
#### timeframe(start_date, end_date, base, currencies) | ||
|
||
- `start_date` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`. | ||
- `end_date` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`. | ||
- `base` <[string]> Optional. Pass in a base currency, defaults to USD. | ||
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for. | ||
|
||
```js | ||
await api.timeframe('2021-04-05', '2021-04-06', 'USD', ['AUD', 'CAD', 'GBP', 'JPY']); | ||
``` | ||
|
||
[Link](https://forexrateapi.com/documentation#api_timeframe) | ||
|
||
--- | ||
#### change(start_date, end_date, base, currencies) | ||
|
||
- `start_date` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`. | ||
- `end_date` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`. | ||
- `base` <[string]> Optional. Pass in a base currency, defaults to USD. | ||
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for. | ||
|
||
```js | ||
await api.change('2021-04-05', '2021-04-06', 'USD', ['AUD', 'CAD', 'GBP', 'JPY']); | ||
``` | ||
|
||
[Link](https://forexrateapi.com/documentation#api_change) | ||
|
||
--- | ||
**[Official documentation](https://forexrateapi.com/documentation)** | ||
|
||
|
||
--- | ||
## FAQ | ||
|
||
- How do I get an API Key? | ||
|
||
Free API Keys are available [here](https://forexrateapi.com). | ||
|
||
- I want more information | ||
|
||
Checkout our FAQs [here](https://forexrateapi.com/faq). | ||
|
||
|
||
## Support | ||
|
||
For support, get in touch using [this form](https://forexrateapi.com/contact). | ||
|
||
|
||
[array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array 'Array' | ||
[number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type 'Number' | ||
[string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type 'String' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const api = require('../index'); | ||
|
||
const apiKey = 'REPLACE_ME'; | ||
|
||
(async function() { | ||
api.setAPIKey(apiKey); | ||
|
||
var result; | ||
|
||
result = await api.fetchSymbols(); | ||
console.log(result.data); | ||
|
||
result = await api.fetchLive('USD', ['AUD', 'CAD', 'GBP', 'JPY']); | ||
console.log(result.data); | ||
|
||
result = await api.fetchHistorical('2021-04-05', 'USD', ['AUD', 'CAD', 'GBP', 'JPY']); | ||
console.log(result.data); | ||
|
||
result = await api.convert('USD', 'EUR', 100, '2021-04-05'); | ||
console.log(result.data); | ||
|
||
result = await api.timeframe('2021-04-05', '2021-04-06', 'USD', ['AUD', 'CAD', 'GBP', 'JPY']); | ||
console.log(result.data); | ||
|
||
result = await api.change('2021-04-05', '2021-04-06', 'USD', ['AUD', 'CAD', 'GBP', 'JPY']); | ||
console.log(result.data); | ||
})(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
(function() { | ||
const axios = require('axios'); | ||
|
||
var apiKey; | ||
|
||
function removeEmpty(obj) { | ||
for (var propName in obj) { | ||
if (obj[propName] === null || obj[propName] === undefined || obj[propName] == '') { | ||
delete obj[propName]; | ||
} | ||
} | ||
return obj; | ||
} | ||
|
||
exports.setAPIKey = function(apiKey) { | ||
this.apiKey = apiKey; | ||
}; | ||
|
||
exports.fetchSymbols = function() { | ||
return axios({ | ||
url: 'https://api.forexrateapi.com/v1/symbols', | ||
params: { | ||
api_key: this.apiKey, | ||
}, | ||
}); | ||
}; | ||
|
||
exports.fetchLive = function(base, currencies) { | ||
return axios({ | ||
url: 'https://api.forexrateapi.com/v1/latest', | ||
params: removeEmpty({ | ||
api_key: this.apiKey, | ||
base: base, | ||
currencies: (currencies || []).join(','), | ||
}), | ||
}); | ||
}; | ||
|
||
exports.fetchHistorical = function(date, base, currencies) { | ||
return axios({ | ||
url: `https://api.forexrateapi.com/v1/${date}`, | ||
params: removeEmpty({ | ||
api_key: this.apiKey, | ||
base: base, | ||
currencies: (currencies || []).join(','), | ||
}), | ||
}); | ||
}; | ||
|
||
exports.convert = function(from, to, amount, date) { | ||
return axios({ | ||
url: 'https://api.forexrateapi.com/v1/convert', | ||
params: removeEmpty({ | ||
api_key: this.apiKey, | ||
from: from, | ||
to: to, | ||
amount: amount, | ||
date: date, | ||
}), | ||
}); | ||
}; | ||
|
||
exports.timeframe = function(startDate, endDate, base, currencies) { | ||
return axios({ | ||
url: 'https://api.forexrateapi.com/v1/timeframe', | ||
params: removeEmpty({ | ||
api_key: this.apiKey, | ||
start_date: startDate, | ||
end_date: endDate, | ||
base: base, | ||
currencies: (currencies || []).join(','), | ||
}), | ||
}); | ||
}; | ||
|
||
exports.change = function(startDate, endDate, base, currencies) { | ||
return axios({ | ||
url: 'https://api.forexrateapi.com/v1/change', | ||
params: removeEmpty({ | ||
api_key: this.apiKey, | ||
start_date: startDate, | ||
end_date: endDate, | ||
base: base, | ||
currencies: (currencies || []).join(','), | ||
}), | ||
}); | ||
} | ||
})(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "forexrateapi", | ||
"version": "1.0.1", | ||
"description": "Official Node.js Library for ForexRateAPI", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "ForexRateAPI", | ||
"license": "GNU GPLv3", | ||
"dependencies": { | ||
"axios": "^0.24.0" | ||
}, | ||
"homepage": "https://forexrateapi.com", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/forexrateapi/forexrateapi-nodejs.git" | ||
}, | ||
"keywords": [ | ||
"foreign exchange rates", | ||
"forex", | ||
"currency coversion", | ||
"currency price", | ||
"currency rates", | ||
"api" | ||
] | ||
} |