Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ jobs:

- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2
with:
parallel: true
flag-name: node-${{ matrix.node-version }}

finish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Close parallel build
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file.

## [2.0.0] - 2026-02-19

### Added
- OHLC (candlestick) endpoint support via `currency.ohlc()`
- `currency()`, `date()`, `interval()`, `base()` methods on the Ohlc class
- Intervals supported: `5m`, `15m`, `30m`, `1h`, `4h`, `12h`, `1d` (default: `1d`)

### Changed
- **Breaking**: Migrated from API v1 to v2 (`/api/v1/` → `/api/v2/`)
- Bumped package version to 2.0.0

## [1.2.0] - 2026-02-13

### Added
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ run: ## Run test file
publish: ## Publish version (use: make publish OTP=123456 if 2FA enabled)
docker run --rm -v ${PWD}:${WORKING_DIR} -v ${HOME}/.npmrc:/home/node/.npmrc:ro -w ${WORKING_DIR} --name ${CONTAINER_NAME} ${LOCAL_DOCKER_IMAGE} npm publish $(if ${OTP},--otp=${OTP})

deprecate: ## Deprecate all v1.x versions on npm (use: make deprecate OTP=123456 if 2FA enabled)
docker run --rm -v ${HOME}/.npmrc:/home/node/.npmrc:ro node:24-slim npm deprecate currencyapi-node@'"<2.0.0"' "The v1 API will redirect to v2 on 31 July 2026. Please upgrade to currencyapi-node@2.0.0 for v2 support and the new OHLC endpoint." $(if ${OTP},--otp=${OTP})

help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# CurrencyApi NodeJs wrapper
# CurrencyApi NodeJs wrapper


[![npm version](https://badge.fury.io/js/currencyapi-node.svg)](https://www.npmjs.com/package/currencyapi-node) [![Coverage Status](https://coveralls.io/repos/github/houseofapis/currencyapi-node/badge.svg?branch=master)](https://coveralls.io/github/houseofapis/currencyapi-node?branch=master)
[![npm version](https://badge.fury.io/js/currencyapi-node.svg)](https://www.npmjs.com/package/currencyapi-node) [![Coverage Status](https://coveralls.io/repos/github/houseofapis/currencyapi-node/badge.svg?branch=master)](https://coveralls.io/github/houseofapis/currencyapi-node?branch=master)

> **Note:** API v1 is deprecated and will be retired on **31st July 2026**, at which point all v1 traffic will be redirected to v2. This SDK (v2.0.0+) targets API v2. If you are on an older version of this SDK, please upgrade.

<a href="https://currencyapi.net" title="CurrencyApi">CurrencyApi.net</a> provides live currency rates via a REST API. A live currency feed for over 152 currencies, including physical (USD, GBP, EUR + more) and cryptos (Bitcoin, Litecoin, Ethereum + more). A JSON and XML currency api updated every 60 seconds.

<a href="https://currencyapi.net" title="CurrencyApi">CurrencyApi.net</a> provides live currency rates via a REST API. A live currency feed for over 152 currencies, including physical (USD, GBP, EUR + more) and cryptos (Bitcoin, Litecoin, Ethereum + more). A JSON and XML currency api updated every 60 seconds.

Features:

Expand All @@ -13,6 +15,7 @@ Features:
- Popular cryptocurrencies included; Bitcoin, Litecoin etc.
- Convert currencies on the fly with the convert endpoint.
- Historical currency rates back to year 2000.
- OHLC (candlestick) data with multiple intervals.
- Easy to follow <a href="https://currencyapi.net/documentation" title="currency-api-documentation">documentation</a>

Signup for a free or paid account <a href="https://currencyapi.net/#pricing-sec" title="currency-api-pricing">here</a>.
Expand Down Expand Up @@ -183,3 +186,38 @@ const result = await currency
| `endDate()` | The historical date you wish to receive the currency conversions until. This should be formatted as YYYY-MM-DD. **Required**. |
| `base()` | The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. **Default: USD**. |
| `output()` | Response output in either JSON or XML. **Default: JSON**. |

<br>

### OHLC (candlestick data):

```javascript
const result = await currency
.ohlc()
.currency('GBP')
.date('2024-01-13')
.get()
```

Example with all available methods:

```javascript
const result = await currency
.ohlc()
.currency('GBP')
.date('2024-01-13')
.interval('1h')
.base('USD')
.output('JSON')
.get()
```

**Available methods for ohlc endpoint**

| Methods | Description |
| --- | --- |
| `currency()` | The quote currency to retrieve OHLC data for. This will be a three letter ISO 4217 currency code. **Required**. |
| `date()` | The date to retrieve OHLC data for. This should be formatted as YYYY-MM-DD. **Required**. |
| `interval()` | The time interval for each candle. Allowed values: `5m`, `15m`, `30m`, `1h`, `4h`, `12h`, `1d`. **Default: 1d**. |
| `base()` | The base currency. **Default: USD**. |
| `output()` | Response output in either JSON or XML. **Default: JSON**. |
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"role": "Developer"
}
],
"version": "1.2.0",
"version": "2.0.0",
"engines": {
"node": ">=16.0.0"
},
Expand Down
10 changes: 10 additions & 0 deletions src/CurrencyApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Convert = require('./classes/Convert')
const History = require('./classes/History')
const Timeframe = require('./classes/Timeframe')
const Currencies = require('./classes/Currencies')
const Ohlc = require('./classes/Ohlc')

/**
* @class CurrencyApi
Expand Down Expand Up @@ -64,6 +65,15 @@ class CurrencyApi
return new Currencies(this.key)
}

/**
* Use the ohlc endpoint
*
* @returns {Ohlc}
*/
ohlc() {
return new Ohlc(this.key)
}

}

module.exports = CurrencyApi
2 changes: 1 addition & 1 deletion src/classes/Endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const BASE_URL = 'https://currencyapi.net/api/';
/**
* Version of the API
*/
const API_VERSION = 'v1';
const API_VERSION = 'v2';

/**
* Default base currency
Expand Down
68 changes: 68 additions & 0 deletions src/classes/Ohlc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const Endpoint = require('./Endpoint')

/**
* Allowed intervals for OHLC data
*/
const ALLOWED_INTERVALS = ['5m', '15m', '30m', '1h', '4h', '12h', '1d']

/**
* @class Ohlc
*/
class Ohlc extends Endpoint {

/**
* Ohlc constructor
*
* @param {string} key
*/
constructor(key) {
super(key, 'ohlc')
this.addParam('interval', '1d')
}

/**
* Set the quote currency
*
* @param {string} currency eg. 'GBP'
* @returns {Ohlc}
*/
currency(currency) {
this.addParam('currency', currency.toUpperCase())
return this
}

/**
* Set the date
*
* @param {string} date eg. '2024-01-13'
* @returns {Ohlc}
*/
date(date) {
this.addParam('date', date)
return this
}

/**
* Set the interval. Allowed values: 5m, 15m, 30m, 1h, 4h, 12h, 1d
*
* @param {string} interval eg. '1h'
* @returns {Ohlc}
*/
interval(interval) {
this.addParam('interval', interval)
return this
}

/**
* Set the base currency
*
* @param {string} currency eg. 'USD'
* @returns {Ohlc}
*/
base(currency) {
this.addParam('base', currency.toUpperCase())
return this
}
}

module.exports = Ohlc
4 changes: 2 additions & 2 deletions tests/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("Fetching convert works as expected", () => {
convert.from('GbP')
convert.to('UsD')
const response = await convert.get();
const expectedUrl = 'https://currencyapi.net/api/v1/convert?key=invalidKey&output=JSON&amount=10&from=GBP&to=USD'
const expectedUrl = 'https://currencyapi.net/api/v2/convert?key=invalidKey&output=JSON&amount=10&from=GBP&to=USD'

expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
headers: {
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("Fetching convert works as expected", () => {
convert.to('UsD')
const response = await convert.get()

const expectedUrl = 'https://currencyapi.net/api/v1/convert?key=invalidKey&output=XML&amount=10&from=GBP&to=USD'
const expectedUrl = 'https://currencyapi.net/api/v2/convert?key=invalidKey&output=XML&amount=10&from=GBP&to=USD'
expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
headers: {
"Content-Type": "application/xml",
Expand Down
4 changes: 2 additions & 2 deletions tests/currencies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("Fetching currencies works as expected", () => {
})
)
const response = await currencies.get();
const expectedUrl = 'https://currencyapi.net/api/v1/currencies?key=invalidKey&output=JSON'
const expectedUrl = 'https://currencyapi.net/api/v2/currencies?key=invalidKey&output=JSON'

expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
headers: {
Expand All @@ -67,7 +67,7 @@ describe("Fetching currencies works as expected", () => {
currencies.output('XmL')
const response = await currencies.get()

const expectedUrl = 'https://currencyapi.net/api/v1/currencies?key=invalidKey&output=XML'
const expectedUrl = 'https://currencyapi.net/api/v2/currencies?key=invalidKey&output=XML'
expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
headers: {
"Content-Type": "application/xml",
Expand Down
2 changes: 2 additions & 0 deletions tests/currencyapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const History = require('./../src/classes/History')
const Timeframe = require('./../src/classes/Timeframe')
const Convert = require('./../src/classes/Convert')
const Currencies = require('./../src/classes/Currencies')
const Ohlc = require('./../src/classes/Ohlc')

let currencyApi
let invalidKey = 'invalidKey'
Expand All @@ -24,5 +25,6 @@ describe("Setting CurrencyApi", () => {
expect(currencyApi.timeframe()).toBeInstanceOf(Timeframe);
expect(currencyApi.convert()).toBeInstanceOf(Convert);
expect(currencyApi.currencies()).toBeInstanceOf(Currencies);
expect(currencyApi.ohlc()).toBeInstanceOf(Ohlc);
})
})
4 changes: 2 additions & 2 deletions tests/history.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("Fetching history works as expected", () => {
)
history.date('2023-01-02')
const response = await history.get();
const expectedUrl = 'https://currencyapi.net/api/v1/history?key=invalidKey&output=JSON&base=USD&date=2023-01-02'
const expectedUrl = 'https://currencyapi.net/api/v2/history?key=invalidKey&output=JSON&base=USD&date=2023-01-02'

expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
headers: {
Expand All @@ -85,7 +85,7 @@ describe("Fetching history works as expected", () => {
history.date('2023-01-02')
history.base('GbP')
const response = await history.get();
const expectedUrl = 'https://currencyapi.net/api/v1/history?key=invalidKey&output=XML&base=GBP&date=2023-01-02'
const expectedUrl = 'https://currencyapi.net/api/v2/history?key=invalidKey&output=XML&base=GBP&date=2023-01-02'

expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
headers: {
Expand Down
Loading