Automatically migrated from Gitolite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
4.3 KiB

6 years ago
  1. # get-exchange-rates
  2. A simple way to get up-to-date exchange rates for Bitcoin and major national currencies. Does *not* require an API key.
  3. # Data format
  4. The base is currently in Euro - this means that the rates will indicate how much `currency` is equivalent to 1 Euro.
  5. Rates are automatically cached for 5 minutes (but this is configurable), and there's currently no historical rate search.
  6. Currently supported currencies (and their sources):
  7. * BTC - Bitcoin (Blockchain.info)
  8. * USD - United States Dollar (ECB, via fixer.io)
  9. * CAD - Canadian Dollar (ECB, via fixer.io)
  10. * GBP - British Pound (ECB, via fixer.io)
  11. * CNY - Chinese Yuan (ECB, via fixer.io)
  12. * RUB - Russian Ruble (ECB, via fixer.io)
  13. * JPY - Japanese Yen (ECB, via fixer.io)
  14. * AUD - Australian Dollar (ECB, via fixer.io)
  15. * NZD - New Zealand Dollar (ECB, via fixer.io)
  16. * BGN - Bulgarian Lev (ECB, via fixer.io)
  17. * BRL - Brazilian Real (ECB, via fixer.io)
  18. * CHF - Swiss Franc (ECB, via fixer.io)
  19. * CZK - Czech Koruna (ECB, via fixer.io)
  20. * DKK - Danish Krone (ECB, via fixer.io)
  21. * HKD - Hong Kong Dollar (ECB, via fixer.io)
  22. * HRK - Croation Kuna (ECB, via fixer.io)
  23. * HUF - Hungarian Forint (ECB, via fixer.io)
  24. * IDR - Indonesian Rupiah (ECB, via fixer.io)
  25. * ILS - Israeli Shekel (ECB, via fixer.io)
  26. * INR - Indian Rupee (ECB, via fixer.io)
  27. * KRW - South Korean Won (ECB, via fixer.io)
  28. * MXN - Mexican Peso (ECB, via fixer.io)
  29. * MYR - Malaysian Ringgit (ECB, via fixer.io)
  30. * NOK - Norwegian Krone (ECB, via fixer.io)
  31. * PHP - Philippine Peso (ECB, via fixer.io)
  32. * PLN - Polish Zloty (ECB, via fixer.io)
  33. * RON - Romanian New Leu (ECB, via fixer.io)
  34. * SEK - Swedish Krona (ECB, via fixer.io)
  35. * SGD - Singapore Dollar (ECB, via fixer.io)
  36. * THB - Thai Baht (ECB, via fixer.io)
  37. * TRY - Turkish Lira (ECB, via fixer.io)
  38. * ZAR - South African Rand (ECB, via fixer.io)
  39. Each currency can be accessed from the result by its 3-letter abbreviation.
  40. Note that fixer.io currencies are subject to change; the module does not currently do any validation, so availability of rates may change if fixer.io or the ECB decides to change them. This list of currencies was up-to-date as of September 20, 2015.
  41. ## License
  42. [WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), whichever you prefer. A donation and/or attribution are appreciated, but not required.
  43. ## Donate
  44. My income consists largely of donations for my projects. If this module is useful to you, consider [making a donation](http://cryto.net/~joepie91/donate.html)!
  45. You can donate using Bitcoin, PayPal, Flattr, cash-in-mail, SEPA transfers, and pretty much anything else.
  46. ## Contributing
  47. Pull requests welcome. Please make sure your modifications are in line with the overall code style, and ensure that you're editing the `.coffee` files, not the `.js` files.
  48. Build tool of choice is `gulp`; simply run `gulp` while developing, and it will watch for changes.
  49. Be aware that by making a pull request, you agree to release your modifications under the licenses stated above.
  50. ## Usage
  51. A simple example:
  52. ```javascript
  53. var Promise = require("bluebird");
  54. var getExchangeRates = require("get-exchange-rates");
  55. Promise.try(function() {
  56. return getExchangeRates();
  57. }).then(function(rates) {
  58. var amountInEuro = 2;
  59. var amountInUSD = amountInEuro * rates.USD;
  60. console.log(amountInEuro + " EUR = " + amountInUSD + " USD");
  61. // eg. "2 EUR = 2.2838 USD"
  62. })
  63. ```
  64. ## API
  65. ### getExchangeRates([cacheExpiration])
  66. Retrieves the exchange rates - either from the cache, or remotely. If retrieved remotely, the results are automatically cached. The rates are *not* rounded - you are responsible for doing this yourself.
  67. Returns a Promise, that resolves with an object containing the rates.
  68. The function will never reject - if either of the APIs is unavailable, the function will simply return stale rates. This may be changed at a later point (and will, in line with semantic versioning, result in a major version bump).
  69. * __cacheExpiration__: *Optional, defaults to 5 minutes.* The duration in seconds, after which the cache should expire. The first call after this duration will result in the cache being repopulated. This option will only take effect if the result is retrieved remotely. __Be respectful to the API operators; please do not set this lower than 5 minutes (300 seconds).__