currencyapi-node 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,15 @@
7
7
  "Bash(git add:*)",
8
8
  "Bash(git commit:*)",
9
9
  "Bash(git push:*)",
10
- "Bash(gh pr create:*)"
10
+ "Bash(gh pr create:*)",
11
+ "Bash(gh pr checks:*)",
12
+ "Bash(gh run view:*)",
13
+ "Bash(git pull:*)",
14
+ "Bash(gh api:*)",
15
+ "Bash(git branch:*)",
16
+ "Bash(git fetch:*)",
17
+ "Bash(git remote set-head:*)",
18
+ "Bash(make:*)"
11
19
  ]
12
20
  }
13
21
  }
@@ -27,3 +27,15 @@ jobs:
27
27
 
28
28
  - name: Upload coverage to Coveralls
29
29
  uses: coverallsapp/github-action@v2
30
+ with:
31
+ parallel: true
32
+ flag-name: node-${{ matrix.node-version }}
33
+
34
+ finish:
35
+ needs: build
36
+ runs-on: ubuntu-latest
37
+ steps:
38
+ - name: Close parallel build
39
+ uses: coverallsapp/github-action@v2
40
+ with:
41
+ parallel-finished: true
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [2.0.0] - 2026-02-19
6
+
7
+ ### Added
8
+ - OHLC (candlestick) endpoint support via `currency.ohlc()`
9
+ - `currency()`, `date()`, `interval()`, `base()` methods on the Ohlc class
10
+ - Intervals supported: `5m`, `15m`, `30m`, `1h`, `4h`, `12h`, `1d` (default: `1d`)
11
+
12
+ ### Changed
13
+ - **Breaking**: Migrated from API v1 to v2 (`/api/v1/` → `/api/v2/`)
14
+ - Bumped package version to 2.0.0
15
+
5
16
  ## [1.2.0] - 2026-02-13
6
17
 
7
18
  ### Added
package/Makefile CHANGED
@@ -22,5 +22,8 @@ run: ## Run test file
22
22
  publish: ## Publish version (use: make publish OTP=123456 if 2FA enabled)
23
23
  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})
24
24
 
25
+ deprecate: ## Deprecate all v1.x versions on npm (use: make deprecate OTP=123456 if 2FA enabled)
26
+ 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})
27
+
25
28
  help:
26
29
  @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
- # CurrencyApi NodeJs wrapper
1
+ # CurrencyApi NodeJs wrapper
2
2
 
3
3
 
4
- [![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)
4
+ [![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=main)](https://coveralls.io/github/houseofapis/currencyapi-node?branch=main)
5
5
 
6
+ > **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.
6
7
 
7
- <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.
8
+
9
+ <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.
8
10
 
9
11
  Features:
10
12
 
@@ -13,6 +15,7 @@ Features:
13
15
  - Popular cryptocurrencies included; Bitcoin, Litecoin etc.
14
16
  - Convert currencies on the fly with the convert endpoint.
15
17
  - Historical currency rates back to year 2000.
18
+ - OHLC (candlestick) data with multiple intervals.
16
19
  - Easy to follow <a href="https://currencyapi.net/documentation" title="currency-api-documentation">documentation</a>
17
20
 
18
21
  Signup for a free or paid account <a href="https://currencyapi.net/#pricing-sec" title="currency-api-pricing">here</a>.
@@ -183,3 +186,38 @@ const result = await currency
183
186
  | `endDate()` | The historical date you wish to receive the currency conversions until. This should be formatted as YYYY-MM-DD. **Required**. |
184
187
  | `base()` | The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. **Default: USD**. |
185
188
  | `output()` | Response output in either JSON or XML. **Default: JSON**. |
189
+
190
+ <br>
191
+
192
+ ### OHLC (candlestick data):
193
+
194
+ ```javascript
195
+ const result = await currency
196
+ .ohlc()
197
+ .currency('GBP')
198
+ .date('2024-01-13')
199
+ .get()
200
+ ```
201
+
202
+ Example with all available methods:
203
+
204
+ ```javascript
205
+ const result = await currency
206
+ .ohlc()
207
+ .currency('GBP')
208
+ .date('2024-01-13')
209
+ .interval('1h')
210
+ .base('USD')
211
+ .output('JSON')
212
+ .get()
213
+ ```
214
+
215
+ **Available methods for ohlc endpoint**
216
+
217
+ | Methods | Description |
218
+ | --- | --- |
219
+ | `currency()` | The quote currency to retrieve OHLC data for. This will be a three letter ISO 4217 currency code. **Required**. |
220
+ | `date()` | The date to retrieve OHLC data for. This should be formatted as YYYY-MM-DD. **Required**. |
221
+ | `interval()` | The time interval for each candle. Allowed values: `5m`, `15m`, `30m`, `1h`, `4h`, `12h`, `1d`. **Default: 1d**. |
222
+ | `base()` | The base currency. **Default: USD**. |
223
+ | `output()` | Response output in either JSON or XML. **Default: JSON**. |
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "role": "Developer"
19
19
  }
20
20
  ],
21
- "version": "1.2.0",
21
+ "version": "2.0.0",
22
22
  "engines": {
23
23
  "node": ">=16.0.0"
24
24
  },
@@ -3,6 +3,7 @@ const Convert = require('./classes/Convert')
3
3
  const History = require('./classes/History')
4
4
  const Timeframe = require('./classes/Timeframe')
5
5
  const Currencies = require('./classes/Currencies')
6
+ const Ohlc = require('./classes/Ohlc')
6
7
 
7
8
  /**
8
9
  * @class CurrencyApi
@@ -64,6 +65,15 @@ class CurrencyApi
64
65
  return new Currencies(this.key)
65
66
  }
66
67
 
68
+ /**
69
+ * Use the ohlc endpoint
70
+ *
71
+ * @returns {Ohlc}
72
+ */
73
+ ohlc() {
74
+ return new Ohlc(this.key)
75
+ }
76
+
67
77
  }
68
78
 
69
79
  module.exports = CurrencyApi
@@ -14,7 +14,7 @@ const BASE_URL = 'https://currencyapi.net/api/';
14
14
  /**
15
15
  * Version of the API
16
16
  */
17
- const API_VERSION = 'v1';
17
+ const API_VERSION = 'v2';
18
18
 
19
19
  /**
20
20
  * Default base currency
@@ -0,0 +1,68 @@
1
+ const Endpoint = require('./Endpoint')
2
+
3
+ /**
4
+ * Allowed intervals for OHLC data
5
+ */
6
+ const ALLOWED_INTERVALS = ['5m', '15m', '30m', '1h', '4h', '12h', '1d']
7
+
8
+ /**
9
+ * @class Ohlc
10
+ */
11
+ class Ohlc extends Endpoint {
12
+
13
+ /**
14
+ * Ohlc constructor
15
+ *
16
+ * @param {string} key
17
+ */
18
+ constructor(key) {
19
+ super(key, 'ohlc')
20
+ this.addParam('interval', '1d')
21
+ }
22
+
23
+ /**
24
+ * Set the quote currency
25
+ *
26
+ * @param {string} currency eg. 'GBP'
27
+ * @returns {Ohlc}
28
+ */
29
+ currency(currency) {
30
+ this.addParam('currency', currency.toUpperCase())
31
+ return this
32
+ }
33
+
34
+ /**
35
+ * Set the date
36
+ *
37
+ * @param {string} date eg. '2024-01-13'
38
+ * @returns {Ohlc}
39
+ */
40
+ date(date) {
41
+ this.addParam('date', date)
42
+ return this
43
+ }
44
+
45
+ /**
46
+ * Set the interval. Allowed values: 5m, 15m, 30m, 1h, 4h, 12h, 1d
47
+ *
48
+ * @param {string} interval eg. '1h'
49
+ * @returns {Ohlc}
50
+ */
51
+ interval(interval) {
52
+ this.addParam('interval', interval)
53
+ return this
54
+ }
55
+
56
+ /**
57
+ * Set the base currency
58
+ *
59
+ * @param {string} currency eg. 'USD'
60
+ * @returns {Ohlc}
61
+ */
62
+ base(currency) {
63
+ this.addParam('base', currency.toUpperCase())
64
+ return this
65
+ }
66
+ }
67
+
68
+ module.exports = Ohlc
@@ -69,7 +69,7 @@ describe("Fetching convert works as expected", () => {
69
69
  convert.from('GbP')
70
70
  convert.to('UsD')
71
71
  const response = await convert.get();
72
- const expectedUrl = 'https://currencyapi.net/api/v1/convert?key=invalidKey&output=JSON&amount=10&from=GBP&to=USD'
72
+ const expectedUrl = 'https://currencyapi.net/api/v2/convert?key=invalidKey&output=JSON&amount=10&from=GBP&to=USD'
73
73
 
74
74
  expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
75
75
  headers: {
@@ -100,7 +100,7 @@ describe("Fetching convert works as expected", () => {
100
100
  convert.to('UsD')
101
101
  const response = await convert.get()
102
102
 
103
- const expectedUrl = 'https://currencyapi.net/api/v1/convert?key=invalidKey&output=XML&amount=10&from=GBP&to=USD'
103
+ const expectedUrl = 'https://currencyapi.net/api/v2/convert?key=invalidKey&output=XML&amount=10&from=GBP&to=USD'
104
104
  expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
105
105
  headers: {
106
106
  "Content-Type": "application/xml",
@@ -42,7 +42,7 @@ describe("Fetching currencies works as expected", () => {
42
42
  })
43
43
  )
44
44
  const response = await currencies.get();
45
- const expectedUrl = 'https://currencyapi.net/api/v1/currencies?key=invalidKey&output=JSON'
45
+ const expectedUrl = 'https://currencyapi.net/api/v2/currencies?key=invalidKey&output=JSON'
46
46
 
47
47
  expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
48
48
  headers: {
@@ -67,7 +67,7 @@ describe("Fetching currencies works as expected", () => {
67
67
  currencies.output('XmL')
68
68
  const response = await currencies.get()
69
69
 
70
- const expectedUrl = 'https://currencyapi.net/api/v1/currencies?key=invalidKey&output=XML'
70
+ const expectedUrl = 'https://currencyapi.net/api/v2/currencies?key=invalidKey&output=XML'
71
71
  expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
72
72
  headers: {
73
73
  "Content-Type": "application/xml",
@@ -4,6 +4,7 @@ const History = require('./../src/classes/History')
4
4
  const Timeframe = require('./../src/classes/Timeframe')
5
5
  const Convert = require('./../src/classes/Convert')
6
6
  const Currencies = require('./../src/classes/Currencies')
7
+ const Ohlc = require('./../src/classes/Ohlc')
7
8
 
8
9
  let currencyApi
9
10
  let invalidKey = 'invalidKey'
@@ -24,5 +25,6 @@ describe("Setting CurrencyApi", () => {
24
25
  expect(currencyApi.timeframe()).toBeInstanceOf(Timeframe);
25
26
  expect(currencyApi.convert()).toBeInstanceOf(Convert);
26
27
  expect(currencyApi.currencies()).toBeInstanceOf(Currencies);
28
+ expect(currencyApi.ohlc()).toBeInstanceOf(Ohlc);
27
29
  })
28
30
  })
@@ -59,7 +59,7 @@ describe("Fetching history works as expected", () => {
59
59
  )
60
60
  history.date('2023-01-02')
61
61
  const response = await history.get();
62
- const expectedUrl = 'https://currencyapi.net/api/v1/history?key=invalidKey&output=JSON&base=USD&date=2023-01-02'
62
+ const expectedUrl = 'https://currencyapi.net/api/v2/history?key=invalidKey&output=JSON&base=USD&date=2023-01-02'
63
63
 
64
64
  expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
65
65
  headers: {
@@ -85,7 +85,7 @@ describe("Fetching history works as expected", () => {
85
85
  history.date('2023-01-02')
86
86
  history.base('GbP')
87
87
  const response = await history.get();
88
- const expectedUrl = 'https://currencyapi.net/api/v1/history?key=invalidKey&output=XML&base=GBP&date=2023-01-02'
88
+ const expectedUrl = 'https://currencyapi.net/api/v2/history?key=invalidKey&output=XML&base=GBP&date=2023-01-02'
89
89
 
90
90
  expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
91
91
  headers: {
@@ -0,0 +1,142 @@
1
+ jest.mock("node-fetch")
2
+ const fetch = require("node-fetch")
3
+ const Ohlc = require('./../src/classes/Ohlc')
4
+
5
+ let ohlc
6
+ let invalidKey = 'invalidKey'
7
+
8
+ beforeEach(() => {
9
+ ohlc = new Ohlc(invalidKey)
10
+ })
11
+
12
+ describe("Setting Ohlc", () => {
13
+
14
+ test('Constructor setting params correctly', () => {
15
+ expect(ohlc.key).toBe(invalidKey)
16
+ expect(ohlc.endpoint).toBe('ohlc')
17
+ })
18
+
19
+ test('Check default params have been set', () => {
20
+ let params = ohlc.getParams()
21
+ expect(params).toHaveProperty('output', 'JSON')
22
+ expect(params).toHaveProperty('interval', '1d')
23
+ })
24
+
25
+ test('Set currency works and returns object', () => {
26
+ const setCurrency = ohlc.currency('gBp')
27
+ let params = ohlc.getParams()
28
+ expect(params).toHaveProperty('currency', 'GBP')
29
+ expect(setCurrency).toBeInstanceOf(Ohlc)
30
+ })
31
+
32
+ test('Set date works and returns object', () => {
33
+ const setDate = ohlc.date('2024-01-13')
34
+ let params = ohlc.getParams()
35
+ expect(params).toHaveProperty('date', '2024-01-13')
36
+ expect(setDate).toBeInstanceOf(Ohlc)
37
+ })
38
+
39
+ test('Set interval works and returns object', () => {
40
+ const setInterval = ohlc.interval('1h')
41
+ let params = ohlc.getParams()
42
+ expect(params).toHaveProperty('interval', '1h')
43
+ expect(setInterval).toBeInstanceOf(Ohlc)
44
+ })
45
+
46
+ test('Set all allowed intervals', () => {
47
+ const intervals = ['5m', '15m', '30m', '1h', '4h', '12h', '1d']
48
+ intervals.forEach(i => {
49
+ ohlc.interval(i)
50
+ expect(ohlc.getParams()).toHaveProperty('interval', i)
51
+ })
52
+ })
53
+
54
+ test('Set base works and returns object', () => {
55
+ const setBase = ohlc.base('eUr')
56
+ let params = ohlc.getParams()
57
+ expect(params).toHaveProperty('base', 'EUR')
58
+ expect(setBase).toBeInstanceOf(Ohlc)
59
+ })
60
+
61
+ test('Set output works and returns object', () => {
62
+ const setOutput = ohlc.output('xMl')
63
+ let params = ohlc.getParams()
64
+ expect(params).toHaveProperty('output', 'XML')
65
+ expect(setOutput).toBeInstanceOf(Ohlc)
66
+ })
67
+
68
+ test('Methods can be chained', () => {
69
+ const result = ohlc.currency('GBP').date('2024-01-13').interval('1h').base('USD')
70
+ expect(result).toBeInstanceOf(Ohlc)
71
+ let params = ohlc.getParams()
72
+ expect(params).toHaveProperty('currency', 'GBP')
73
+ expect(params).toHaveProperty('date', '2024-01-13')
74
+ expect(params).toHaveProperty('interval', '1h')
75
+ expect(params).toHaveProperty('base', 'USD')
76
+ })
77
+
78
+ })
79
+
80
+ describe("Fetching ohlc works as expected", () => {
81
+
82
+ test("fetch json working as expected", async () => {
83
+
84
+ const mockData = {
85
+ "valid": true,
86
+ "base": "USD",
87
+ "quote": "GBP",
88
+ "date": "2024-01-13",
89
+ "interval": "1h",
90
+ "ohlc": [
91
+ {
92
+ "start": "2024-01-13T00:00:00Z",
93
+ "open": 1.2735,
94
+ "high": 1.2756,
95
+ "low": 1.2720,
96
+ "close": 1.2748
97
+ }
98
+ ]
99
+ }
100
+ fetch.mockReturnValue(
101
+ Promise.resolve({
102
+ json: () =>
103
+ Promise.resolve(mockData)
104
+ })
105
+ )
106
+ ohlc.currency('GBP').date('2024-01-13').interval('1h')
107
+ const response = await ohlc.get()
108
+ const expectedUrl = 'https://currencyapi.net/api/v2/ohlc?key=invalidKey&output=JSON&interval=1h&currency=GBP&date=2024-01-13'
109
+
110
+ expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
111
+ headers: {
112
+ "Content-Type": "application/json",
113
+ "X-Sdk": "node"
114
+ }
115
+ })
116
+ expect(response).toEqual(mockData)
117
+ })
118
+
119
+ test("fetch xml working as expected", async () => {
120
+
121
+ const mockData = ''
122
+
123
+ fetch.mockReturnValue(
124
+ Promise.resolve({
125
+ text: () =>
126
+ Promise.resolve(mockData)
127
+ })
128
+ )
129
+ ohlc.output('XmL').currency('GBP').date('2024-01-13')
130
+ const response = await ohlc.get()
131
+
132
+ const expectedUrl = 'https://currencyapi.net/api/v2/ohlc?key=invalidKey&output=XML&interval=1d&currency=GBP&date=2024-01-13'
133
+ expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
134
+ headers: {
135
+ "Content-Type": "application/xml",
136
+ "X-Sdk": "node"
137
+ }
138
+ })
139
+ expect(response).toEqual(mockData)
140
+ })
141
+
142
+ })
@@ -62,7 +62,7 @@ describe("Fetching rates works as expected", () => {
62
62
  })
63
63
  )
64
64
  const response = await rates.get();
65
- expect(fetch).toHaveBeenLastCalledWith("https://currencyapi.net/api/v1/rates?key=invalidKey&output=JSON&base=USD", {
65
+ expect(fetch).toHaveBeenLastCalledWith("https://currencyapi.net/api/v2/rates?key=invalidKey&output=JSON&base=USD", {
66
66
  headers: {
67
67
  "Content-Type": "application/json",
68
68
  "X-Sdk": "node"
@@ -91,7 +91,7 @@ describe("Fetching rates works as expected", () => {
91
91
  rates.output('XmL')
92
92
  const response = await rates.get()
93
93
 
94
- expect(fetch).toHaveBeenLastCalledWith("https://currencyapi.net/api/v1/rates?key=invalidKey&output=XML&base=USD", {
94
+ expect(fetch).toHaveBeenLastCalledWith("https://currencyapi.net/api/v2/rates?key=invalidKey&output=XML&base=USD", {
95
95
  headers: {
96
96
  "Content-Type": "application/xml",
97
97
  "X-Sdk": "node"
@@ -69,7 +69,7 @@ describe("Fetching timeframe works as expected", () => {
69
69
  timeframe.startDate('2023-01-02')
70
70
  timeframe.endDate('2023-01-03')
71
71
  const response = await timeframe.get();
72
- const expectedUrl = 'https://currencyapi.net/api/v1/timeframe?key=invalidKey&output=JSON&base=USD&start_date=2023-01-02&end_date=2023-01-03'
72
+ const expectedUrl = 'https://currencyapi.net/api/v2/timeframe?key=invalidKey&output=JSON&base=USD&start_date=2023-01-02&end_date=2023-01-03'
73
73
 
74
74
  expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
75
75
  headers: {
@@ -96,7 +96,7 @@ describe("Fetching timeframe works as expected", () => {
96
96
  timeframe.startDate('2023-01-02')
97
97
  timeframe.endDate('2023-01-03')
98
98
  const response = await timeframe.get();
99
- const expectedUrl = 'https://currencyapi.net/api/v1/timeframe?key=invalidKey&output=XML&base=USD&start_date=2023-01-02&end_date=2023-01-03'
99
+ const expectedUrl = 'https://currencyapi.net/api/v2/timeframe?key=invalidKey&output=XML&base=USD&start_date=2023-01-02&end_date=2023-01-03'
100
100
 
101
101
  expect(fetch).toHaveBeenLastCalledWith(expectedUrl, {
102
102
  headers: {