diff --git a/README.md b/README.md index c5f6fe1..e6e5bbe 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) @@ -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) @@ -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)** diff --git a/example.py b/example.py index 44b066b..3007a61 100644 --- a/example.py +++ b/example.py @@ -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) diff --git a/metalpriceapi/client.py b/metalpriceapi/client.py index d90c8ef..96a44be 100644 --- a/metalpriceapi/client.py +++ b/metalpriceapi/client.py @@ -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() diff --git a/requirements.txt b/requirements.txt index 28fbc91..37912b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -requests>=2.9.1 +requests>=2.31.0 \ No newline at end of file diff --git a/setup.py b/setup.py index a6faad0..bae223a 100644 --- a/setup.py +++ b/setup.py @@ -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", @@ -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'], )