https://github.com/autonomoussoftware/safe-exchange-rate
Safely get exchange rates
https://github.com/autonomoussoftware/safe-exchange-rate
Last synced: about 1 year ago
JSON representation
Safely get exchange rates
- Host: GitHub
- URL: https://github.com/autonomoussoftware/safe-exchange-rate
- Owner: autonomoussoftware
- License: mit
- Created: 2019-09-19T23:55:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-06T17:46:46.000Z (almost 5 years ago)
- Last Synced: 2025-02-23T17:17:41.907Z (over 1 year ago)
- Language: JavaScript
- Size: 317 KB
- Stars: 1
- Watchers: 8
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# safe-exchange-rate
[](https://travis-ci.com/autonomoussoftware/safe-exchange-rate)
[](https://github.com/bloq/eslint-config-bloq)
[](https://snyk.io/test/github/autonomoussoftware/safe-exchange-rate?targetFile=package.json)
Safely get exchange rates from different providers.
If any provider is down or failing, a different one from an internal list will be used.
The following exchange rate pairs are currently supported:
- BAT:USD
- ETH:USD
- DAI:USD
- ETC:USD
- KNC:USD
- MANA:USD
- QTUM:USD
- USDC:USD
- WBTC:USD
- ZRX:USD
Only 100% open and free providers are queried:
- [Bittrex](https://bittrex.com)
- [CoinCap](https://coincap.io)
- [CoinGecko](https://coingecko.com)
## Installation
```shell
npm install safe-exchange-rate
```
## Usage
```js
const getExchangeRate = require('safe-exchange-rate')
getExchangeRate('ETH:USD').then(function (rate) {
console.log(rate) // 225.68
}
```
## API
### getExchangeRate(pair) ⇒ `Promise`
Obtain the exchange rate between two assets given list of providers. If one
fails for any reason, the next in the list is used. The providers include:
Bittrex, CoinCap, CoinGecko.
**Returns**: `Promise` - The exchange rate.
| Param | Type | Description |
| ----- | -------- | ----------------------------- |
| pair | `string` | The rate pair like `ETH:USD`. |
## License
MIT