Skip to content

Commit

Permalink
v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
metalpriceapi-user committed Feb 22, 2024
1 parent bc00fbf commit 4187f8b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ client.fetchLive(base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
- `currencies` <[List]<[string]>> Optional. Pass in an list of currencies to return values for.

```python
client.fetchHistorical(date='2021-04-05', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
client.fetchHistorical(date='2024-02-05', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
```

[Link](https://metalpriceapi.com/documentation#api_historical)
Expand All @@ -61,7 +61,7 @@ client.fetchHistorical(date='2021-04-05', base='USD', currencies=['XAU', 'XAG',
- `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.

```python
client.convert(from_currency='USD', to_currency='EUR', amount=100, date='2021-04-05')
client.convert(from_currency='USD', to_currency='EUR', amount=100, date='2024-02-05')
```

[Link](https://metalpriceapi.com/documentation#api_convert)
Expand All @@ -75,7 +75,7 @@ client.convert(from_currency='USD', to_currency='EUR', amount=100, date='2021-04
- `currencies` <[List]<[string]>> Optional. Pass in an list of currencies to return values for.

```python
client.timeframe(start_date='2021-04-05', end_date='2021-04-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
client.timeframe(start_date='2024-02-05', end_date='2024-02-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
```

[Link](https://metalpriceapi.com/documentation#api_timeframe)
Expand All @@ -89,11 +89,23 @@ client.timeframe(start_date='2021-04-05', end_date='2021-04-06', base='USD', cur
- `currencies` <[List]<[string]>> Optional. Pass in an list of currencies to return values for.

```python
client.change(start_date='2021-04-05', end_date='2021-04-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
client.change(start_date='2024-02-05', end_date='2024-02-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
```

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

---
#### carat(base, date)

- `base` <[string]> Optional. Pass in a base currency, defaults to USD.
- `date` <[string]> Optional. Specify date to get Carat for specific date using format `YYYY-MM-DD`. If not specified, uses live rates.

```python
client.carat(base='USD', date='2024-02-05')
```

[Link](https://metalpriceapi.com/documentation#api_carat)

---
**[Official documentation](https://metalpriceapi.com/documentation)**

Expand Down
11 changes: 7 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
result = client.fetchLive(base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
print(result)

result = client.fetchHistorical(date='2021-04-05', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
result = client.fetchHistorical(date='2024-02-05', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
print(result)

result = client.convert(from_currency='USD', to_currency='EUR', amount=100, date='2021-04-05')
result = client.convert(from_currency='USD', to_currency='EUR', amount=100, date='2024-02-05')
print(result)

result = client.timeframe(start_date='2021-04-05', end_date='2021-04-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
result = client.timeframe(start_date='2024-02-05', end_date='2024-02-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
print(result)

result = client.change(start_date='2021-04-05', end_date='2021-04-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
result = client.change(start_date='2024-02-05', end_date='2024-02-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
print(result)

result = client.carat(base='USD', date='2024-02-06')
print(result)
8 changes: 8 additions & 0 deletions metalpriceapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@ def change(self, start_date, end_date, base='', currencies=[]):
})
response = self.client.get(f'{self.base_url}/change', params=params)
return response.json()

def carat(self, base='', date = ''):
params = self._removeEmpty({
'base': base,
'date': date,
})
response = self.client.get(f'{self.base_url}/carat', params=params)
return response.json()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests>=2.9.1
requests>=2.31.0
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="metalpriceapi",
version="1.0.3",
version="1.0.4",
url="https://github.com/metalpriceapi/metalpriceapi-python",

author="MetalpriceAPI",
Expand All @@ -14,6 +14,6 @@

packages=setuptools.find_packages(),

install_requires=['requests>=2.9.1'],
install_requires=['requests>=2.31.0'],
keywords=['currency', 'metal price', 'exchangerate', 'rates'],
)

0 comments on commit 4187f8b

Please sign in to comment.