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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

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

## [2.1.0] - 2026-02-22

### Changed
- OHLC endpoint: renamed `currency()` to `quote()` and request parameter from `currency` to `quote` to align with API response field names.

## [2.0.0] - 2026-02-19

### Added
Expand Down
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
.PHONY: help
LOCAL_DOCKER_IMAGE=houseofapis/currencyapi-node
CONTAINER_NAME=currencyapi-node-sdk
WORKING_DIR=/application
WORKING_DIR=/app
PORT=7003
DOCKER_COMMAND=docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} ${LOCAL_DOCKER_IMAGE}
DOCKER_COMMAND_INTERACTIVE=docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} -it ${LOCAL_DOCKER_IMAGE}
# Use official image so test/run work without building
DOCKER_IMAGE ?= node:24-slim
DOCKER_RUN = docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT}
DOCKER_RUN_IT = docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} -it

build: ## Build docker image
docker build -t ${LOCAL_DOCKER_IMAGE} . --no-cache

test: ## Run the tests
${DOCKER_COMMAND} npm test
test: ## Run the tests (no build required)
${DOCKER_RUN} ${DOCKER_IMAGE} sh -c "npm ci 2>/dev/null || npm install && npm test"

install: ## Npm install
${DOCKER_COMMAND} npm i
${DOCKER_RUN} ${DOCKER_IMAGE} npm ci 2>/dev/null || ${DOCKER_RUN} ${DOCKER_IMAGE} npm install

run: ## Run test file
${DOCKER_COMMAND_INTERACTIVE} node run.js
run: ## Run the run file (no build required)
${DOCKER_RUN_IT} ${DOCKER_IMAGE} sh -c "npm ci 2>/dev/null || npm install && node run.js"

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})
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const result = await currency
```javascript
const result = await currency
.ohlc()
.currency('GBP')
.quote('GBP')
.date('2024-01-13')
.get()
```
Expand All @@ -204,7 +204,7 @@ Example with all available methods:
```javascript
const result = await currency
.ohlc()
.currency('GBP')
.quote('GBP')
.date('2024-01-13')
.interval('1h')
.base('USD')
Expand All @@ -216,7 +216,7 @@ const result = await currency

| Methods | Description |
| --- | --- |
| `currency()` | The quote currency to retrieve OHLC data for. This will be a three letter ISO 4217 currency code. **Required**. |
| `quote()` | 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**. |
Expand Down
6 changes: 3 additions & 3 deletions src/classes/Ohlc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class Ohlc extends Endpoint {
/**
* Set the quote currency
*
* @param {string} currency eg. 'GBP'
* @param {string} quote eg. 'GBP'
* @returns {Ohlc}
*/
currency(currency) {
this.addParam('currency', currency.toUpperCase())
quote(quote) {
this.addParam('quote', quote.toUpperCase())
return this
}

Expand Down
20 changes: 10 additions & 10 deletions tests/ohlc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ describe("Setting Ohlc", () => {
expect(params).toHaveProperty('interval', '1d')
})

test('Set currency works and returns object', () => {
const setCurrency = ohlc.currency('gBp')
test('Set quote works and returns object', () => {
const setQuote = ohlc.quote('gBp')
let params = ohlc.getParams()
expect(params).toHaveProperty('currency', 'GBP')
expect(setCurrency).toBeInstanceOf(Ohlc)
expect(params).toHaveProperty('quote', 'GBP')
expect(setQuote).toBeInstanceOf(Ohlc)
})

test('Set date works and returns object', () => {
Expand Down Expand Up @@ -66,10 +66,10 @@ describe("Setting Ohlc", () => {
})

test('Methods can be chained', () => {
const result = ohlc.currency('GBP').date('2024-01-13').interval('1h').base('USD')
const result = ohlc.quote('GBP').date('2024-01-13').interval('1h').base('USD')
expect(result).toBeInstanceOf(Ohlc)
let params = ohlc.getParams()
expect(params).toHaveProperty('currency', 'GBP')
expect(params).toHaveProperty('quote', 'GBP')
expect(params).toHaveProperty('date', '2024-01-13')
expect(params).toHaveProperty('interval', '1h')
expect(params).toHaveProperty('base', 'USD')
Expand Down Expand Up @@ -103,9 +103,9 @@ describe("Fetching ohlc works as expected", () => {
Promise.resolve(mockData)
})
)
ohlc.currency('GBP').date('2024-01-13').interval('1h')
ohlc.quote('GBP').date('2024-01-13').interval('1h')
const response = await ohlc.get()
const expectedUrl = 'https://currencyapi.net/api/v2/ohlc?key=invalidKey&output=JSON&interval=1h&currency=GBP&date=2024-01-13'
const expectedUrl = 'https://currencyapi.net/api/v2/ohlc?key=invalidKey&output=JSON&interval=1h&quote=GBP&date=2024-01-13'

expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
headers: {
Expand All @@ -126,10 +126,10 @@ describe("Fetching ohlc works as expected", () => {
Promise.resolve(mockData)
})
)
ohlc.output('XmL').currency('GBP').date('2024-01-13')
ohlc.output('XmL').quote('GBP').date('2024-01-13')
const response = await ohlc.get()

const expectedUrl = 'https://currencyapi.net/api/v2/ohlc?key=invalidKey&output=XML&interval=1d&currency=GBP&date=2024-01-13'
const expectedUrl = 'https://currencyapi.net/api/v2/ohlc?key=invalidKey&output=XML&interval=1d&quote=GBP&date=2024-01-13'
expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
headers: {
"Content-Type": "application/xml",
Expand Down