currencyapi-node 1.1.1 → 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.
@@ -0,0 +1,21 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(git checkout:*)",
5
+ "Bash(docker build:*)",
6
+ "Bash(npm install:*)",
7
+ "Bash(git add:*)",
8
+ "Bash(git commit:*)",
9
+ "Bash(git push:*)",
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:*)"
19
+ ]
20
+ }
21
+ }
@@ -8,14 +8,14 @@ jobs:
8
8
 
9
9
  strategy:
10
10
  matrix:
11
- node-version: [14.x, 15.x, 16.x, 18.x]
11
+ node-version: [16.x, 18.x, 20.x, 22.x, 24.x]
12
12
 
13
13
  steps:
14
14
  - name: Checkout repository
15
- uses: actions/checkout@v2
15
+ uses: actions/checkout@v4
16
16
 
17
17
  - name: Set up Node.js ${{ matrix.node-version }}
18
- uses: actions/setup-node@v1
18
+ uses: actions/setup-node@v4
19
19
  with:
20
20
  node-version: ${{ matrix.node-version }}
21
21
 
@@ -26,4 +26,16 @@ jobs:
26
26
  run: npm run test
27
27
 
28
28
  - name: Upload coverage to Coveralls
29
- uses: coverallsapp/github-action@v2
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 ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
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
+
16
+ ## [1.2.0] - 2026-02-13
17
+
18
+ ### Added
19
+ - Node.js v20, v22, and v24 support
20
+ - `engines` field in package.json specifying minimum Node.js version
21
+
22
+ ### Changed
23
+ - Dockerfile updated from Node 22 to Node 24
24
+ - CI matrix updated to test against Node.js 16, 18, 20, 22, and 24
25
+ - Updated GitHub Actions to latest versions (checkout@v4, setup-node@v4)
26
+ - Minimum supported Node.js version updated from v8 to v16
27
+ - README updated to reflect current Node.js compatibility
28
+
29
+ ## [1.1.1] - Previous release
30
+
31
+ - Initial tracked version
package/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM node:18-slim
1
+ FROM node:24-slim
2
2
 
3
3
  USER node
4
4
  ARG APP_DIR=/home/node/app
package/Makefile CHANGED
@@ -1,10 +1,11 @@
1
1
  .DEFAULT_GOAL := help
2
2
  .PHONY: help
3
3
  LOCAL_DOCKER_IMAGE=houseofapis/currencyapi-node
4
- CONTAINER_NAME=currencyapi-node
4
+ CONTAINER_NAME=currencyapi-node-sdk
5
5
  WORKING_DIR=/application
6
6
  PORT=7003
7
- DOCKER_COMMAND=docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} -it ${LOCAL_DOCKER_IMAGE}
7
+ DOCKER_COMMAND=docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} ${LOCAL_DOCKER_IMAGE}
8
+ DOCKER_COMMAND_INTERACTIVE=docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} -it ${LOCAL_DOCKER_IMAGE}
8
9
 
9
10
  build: ## Build docker image
10
11
  docker build -t ${LOCAL_DOCKER_IMAGE} . --no-cache
@@ -16,7 +17,13 @@ install: ## Npm install
16
17
  ${DOCKER_COMMAND} npm i
17
18
 
18
19
  run: ## Run test file
19
- ${DOCKER_COMMAND} npm publish
20
+ ${DOCKER_COMMAND_INTERACTIVE} node run.js
21
+
22
+ publish: ## Publish version (use: make publish OTP=123456 if 2FA enabled)
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
+
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})
20
27
 
21
28
  help:
22
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,18 +15,25 @@ 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>.
19
22
 
20
- ## This package
23
+ ## This package is a:
21
24
 
22
25
  NodeJs wrapper for <a href="https://currencyapi.net" title="CurrencyApi">CurrencyApi.net</a> endpoints.
23
26
 
27
+ ## Developer Guide
28
+
29
+ For an easy to following developer guide, check out our [NodeJs Developer Guide](https://currencyapi.net/sdk/nodejs).
30
+
31
+ Alternatively keep reading below.
32
+
24
33
  #### Prerequisites
25
34
 
26
- - Minimum NodeJs v8 (npm v5 and above)
27
- - Working on NodeJs v18
35
+ - Minimum NodeJs v16 (npm v7 and above)
36
+ - Tested on NodeJs v16, v18, v20, v22, v24
28
37
  - Free or Paid account with CurrencyApi.net
29
38
 
30
39
  #### Test Coverage
@@ -177,3 +186,38 @@ const result = await currency
177
186
  | `endDate()` | The historical date you wish to receive the currency conversions until. This should be formatted as YYYY-MM-DD. **Required**. |
178
187
  | `base()` | The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. **Default: USD**. |
179
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,10 @@
18
18
  "role": "Developer"
19
19
  }
20
20
  ],
21
- "version": "1.1.1",
21
+ "version": "2.0.0",
22
+ "engines": {
23
+ "node": ">=16.0.0"
24
+ },
22
25
  "scripts": {
23
26
  "test": "jest --coverage --collectCoverageFrom='./src/**'"
24
27
  },
package/run.js CHANGED
@@ -1,6 +1,26 @@
1
- const CurrencyApi = require('./src/CurrencyApi')
1
+ // run.js
2
+ const CurrencyApi = require('./src/CurrencyApi');
2
3
 
3
- const currency = new CurrencyApi('API_KEY');
4
- currency.rates().output('JSON').get()
5
- .then(console.log)
4
+ const currency = new CurrencyApi('YOUR_API_KEY');
6
5
 
6
+ async function convertCurrency(amount, fromCurrency, toCurrency) {
7
+ try {
8
+ const result = await currency.convert()
9
+ .from(fromCurrency)
10
+ .to(toCurrency)
11
+ .amount(amount)
12
+ .get();
13
+ return result.conversion.result;
14
+ } catch (error) {
15
+ throw new Error(`Conversion failed: ${error.message}`);
16
+ }
17
+ }
18
+
19
+ (async () => {
20
+ try {
21
+ const converted = await convertCurrency(100, 'BTC', 'USD');
22
+ console.log(`100 BTC is equal to ${converted} USD`);
23
+ } catch (error) {
24
+ console.error(error);
25
+ }
26
+ })();
@@ -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: {