Skip to content

Commit da7001b

Browse files
version 1.0.1
1 parent 93c8ae0 commit da7001b

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ await api.fetchLive('USD', ['XAU', 'XAG', 'XPD', 'XPT']);
6060
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
6161

6262
```js
63-
await api.fetchHistorical('2021-04-05', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
63+
await api.fetchHistorical('2024-02-05', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
6464
```
6565

6666
[Link](https://metalpriceapi.com/documentation#api_historical)
@@ -74,7 +74,7 @@ await api.fetchHistorical('2021-04-05', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
7474
- `date` <[string]> Optional. Specify date to use historical midpoint value for conversion with format `YYYY-MM-DD`. Otherwise, it will use live exchange rate date if value not passed in.
7575

7676
```js
77-
await api.convert('USD', 'EUR', 100, '2021-04-05');
77+
await api.convert('USD', 'EUR', 100, '2024-02-05');
7878
```
7979

8080
[Link](https://metalpriceapi.com/documentation#api_convert)
@@ -88,7 +88,7 @@ await api.convert('USD', 'EUR', 100, '2021-04-05');
8888
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
8989

9090
```js
91-
await api.timeframe('2021-04-05', '2021-04-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
91+
await api.timeframe('2024-02-05', '2024-02-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
9292
```
9393

9494
[Link](https://metalpriceapi.com/documentation#api_timeframe)
@@ -102,11 +102,23 @@ await api.timeframe('2021-04-05', '2021-04-06', 'USD', ['XAU', 'XAG', 'XPD', 'XP
102102
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
103103

104104
```js
105-
await api.change('2021-04-05', '2021-04-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
105+
await api.change('2024-02-05', '2024-02-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
106106
```
107107

108108
[Link](https://metalpriceapi.com/documentation#api_change)
109109

110+
---
111+
#### carat(base, date)
112+
113+
- `base` <[string]> Optional. Pass in a base currency, defaults to USD.
114+
- `date` <[string]> Optional. Specify date to get Carat using format `YYYY-MM-DD`. If not specified, uses live rates.
115+
116+
```js
117+
await api.carat('USD', '2024-02-06');
118+
```
119+
120+
[Link](https://metalpriceapi.com/documentation#api_carat)
121+
110122
---
111123
**[Official documentation](https://metalpriceapi.com/documentation)**
112124

example/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const api = require('../index');
2+
// const api = require('metalpriceapi');
23

34
const apiKey = 'REPLACE_ME';
45

@@ -13,15 +14,15 @@ const apiKey = 'REPLACE_ME';
1314
result = await api.fetchLive('USD', ['XAU', 'XAG', 'XPD', 'XPT']);
1415
console.log(result.data);
1516

16-
result = await api.fetchHistorical('2021-04-05', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
17+
result = await api.fetchHistorical('2024-02-05', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
1718
console.log(result.data);
1819

19-
result = await api.convert('USD', 'EUR', 100, '2021-04-05');
20+
result = await api.convert('USD', 'EUR', 100, '2024-02-05');
2021
console.log(result.data);
2122

22-
result = await api.timeframe('2021-04-05', '2021-04-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
23+
result = await api.timeframe('2024-02-05', '2024-02-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
2324
console.log(result.data);
2425

25-
result = await api.change('2021-04-05', '2021-04-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
26+
result = await api.change('2024-02-05', '2024-02-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT']);
2627
console.log(result.data);
2728
})();

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,15 @@
8585
}),
8686
});
8787
}
88+
89+
exports.carat = function(base, date) {
90+
return axios({
91+
url: 'https://api.metalpriceapi.com/v1/carat',
92+
params: removeEmpty({
93+
api_key: this.apiKey,
94+
base: base,
95+
date: date,
96+
}),
97+
});
98+
}
8899
})();

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "metalpriceapi",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Official Node.js Library for MetalpriceAPI",
55
"main": "index.js",
66
"scripts": {
@@ -9,7 +9,7 @@
99
"author": "MetalpriceAPI",
1010
"license": "GNU GPLv3",
1111
"dependencies": {
12-
"axios": "^0.24.0"
12+
"axios": "^1.6.7"
1313
},
1414
"homepage": "https://metalpriceapi.com",
1515
"repository": {

0 commit comments

Comments
 (0)