### Installation Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Instructions for installing the metalpriceapi Python wrapper using pip. ```APIDOC ## Installation Install the latest release with: ```bash pip install metalpriceapi ``` ``` -------------------------------- ### Complete Integration Example with MetalPriceAPI Python Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt A full example demonstrating error handling, making multiple API calls sequentially, and processing the returned data. This showcases a more robust implementation of the metalpriceapi-python client. ```python from metalpriceapi.client import Client import json ``` -------------------------------- ### Install metalpriceapi Python Wrapper Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Installs the latest version of the metalpriceapi Python wrapper using pip. This is the primary step to integrate the API into your Python applications. ```bash pip install metalpriceapi ``` -------------------------------- ### Convert Currencies with MetalPriceAPI Python Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Demonstrates how to convert between fiat currencies and precious metals (like gold, XAU) using historical or live rates. Requires the metalpriceapi library to be installed and an API key for initialization. ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Convert 100 USD to EUR using historical rates result = client.convert( from_currency='USD', to_currency='EUR', amount=100, date='2024-02-05' ) print(result) # Convert USD to gold using live rates result = client.convert( from_currency='USD', to_currency='XAU', amount=2000 ) print(result) # Convert gold to USD result = client.convert( to_currency='USD', from_currency='XAU', amount=1 ) print(result) ``` -------------------------------- ### Fetch Live Metal Prices Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Get real-time metal prices with optional base currency and specific metal symbols filtering. ```APIDOC ## Fetch Live Metal Prices ### Description Get real-time metal prices with optional base currency and specific metal symbols filtering. ### Method `fetchLive(base='USD', currencies=[])` ### Endpoint N/A (Method call on client object) ### Parameters #### Path Parameters None #### Query Parameters - **base** (string) - Optional. The base currency or metal symbol (e.g., 'USD', 'EUR', 'XAU'). Defaults to 'USD'. - **currencies** (array of strings) - Optional. An array of currency or metal symbols to fetch prices for (e.g., ['XAU', 'XAG']). If empty, all available rates are returned. #### Request Body None ### Request Example ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Fetch live prices for specific metals in USD result = client.fetchLive(base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT']) print(result) # Fetch all available rates with EUR as base result = client.fetchLive(base='EUR', currencies=[]) print(result) # Use default USD base with no filtering result = client.fetchLive() print(result) ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **base** (string) - The base currency or metal symbol used for the rates. - **timestamp** (integer) - The Unix timestamp of the rates. - **rates** (object) - A key-value map of currency or metal symbols and their corresponding prices relative to the base. #### Response Example ```json { "success": true, "base": "USD", "timestamp": 1707139200, "rates": { "XAU": 0.0004951, # Price of 1 USD in troy ounces of gold "XAG": 0.0431, # Price of 1 USD in troy ounces of silver "XPD": 0.0010, # Price of 1 USD in troy ounces of palladium "XPT": 0.0011 # Price of 1 USD in troy ounces of platinum } } ``` ``` -------------------------------- ### Fetch Metal Prices Over a Timeframe (Python) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Retrieves metal prices over a specified date range. Requires start and end dates in 'YYYY-MM-DD' format, with optional base currency and list of currencies. ```python client.timeframe(start_date='2024-02-05', end_date='2024-02-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT']) ``` -------------------------------- ### Fetch Metal Price Changes Over a Timeframe (Python) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Calculates the change in metal prices over a specified date range. Requires start and end dates in 'YYYY-MM-DD' format, with optional base currency and list of currencies. ```python client.change(start_date='2024-02-05', end_date='2024-02-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT']) ``` -------------------------------- ### Client Initialization Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Demonstrates how to initialize the MetalPriceAPI client with your API key. ```APIDOC ## Usage ```python from metalpriceapi.client import Client api_key = 'SET_YOUR_API_KEY_HERE' client = Client(api_key) ``` ``` -------------------------------- ### Initialize metalpriceapi Client Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Demonstrates how to initialize the `Client` object from the metalpriceapi library. Requires an API key to be set, which can be obtained from metalpriceapi.com. ```python from metalpriceapi.client import Client api_key = 'SET_YOUR_API_KEY_HERE' client = Client(api_key) ``` -------------------------------- ### Client Initialization Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Initialize the MetalpriceAPI client with your API key to authenticate all subsequent requests. ```APIDOC ## Client Initialization ### Description Initialize the MetalpriceAPI client with your API key to authenticate all subsequent requests. ### Method N/A (Class Constructor) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from metalpriceapi.client import Client # Initialize client with API key api_key = 'your_api_key_here' client = Client(api_key) ``` ### Response N/A (Object instantiation) ``` -------------------------------- ### fetchLive(base, currencies) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Retrieves live metal prices for specified currencies. ```APIDOC #### fetchLive(base, currencies) Retrieves live metal prices. - `base` <[string]> Optional. Pass in a base currency, defaults to USD. - `currencies` <[List]<[string]>> Optional. Pass in an list of currencies to return values for. ```python client.fetchLive(base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT']) ``` [Link](https://metalpriceapi.com/documentation#api_realtime) ``` -------------------------------- ### Initialize MetalpriceAPI Client (Python) Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Initializes the MetalpriceAPI client using your API key for authentication. This client object is then used for all subsequent API calls. ```python from metalpriceapi.client import Client # Initialize client with API key api_key = 'your_api_key_here' client = Client(api_key) # The client maintains a session with your API key # All subsequent API calls will be authenticated automatically ``` -------------------------------- ### usage() Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Retrieves information about your API usage. ```APIDOC #### usage() Retrieves information about your API usage. ```python client.usage() ``` [Link](https://metalpriceapi.com/documentation#api_usage) ``` -------------------------------- ### fetchSymbols() Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Fetches a list of available currency symbols supported by the API. ```APIDOC ## Documentation #### fetchSymbols() Fetches a list of all available currency symbols. ```python client.fetchSymbols() ``` [Link](https://metalpriceapi.com/documentation#api_symbol) ``` -------------------------------- ### Fetch Live Metal Prices (Python) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Fetches live metal prices for specified currencies against a base currency. Supports optional base currency and a list of target currencies. ```python client.fetchLive(base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT']) ``` -------------------------------- ### Fetch Precious Metal Prices and Convert with Python Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Initializes the MetalpriceAPI client, fetches available metal symbols, retrieves live prices for gold (XAU) and silver (XAG) in USD, calculates their price per troy ounce, performs a USD to XAU conversion, analyzes price changes over a week, and checks API usage. Requires an API key. Handles potential exceptions. ```python from metalpriceapi import Client api_key = 'your_api_key_here' client = Client(api_key) try: symbols = client.fetchSymbols() print("Available metals:", [k for k in symbols.get('symbols', {}).keys() if k.startswith('X')]) live_prices = client.fetchLive(base='USD', currencies=['XAU', 'XAG']) if live_prices.get('success'): xau_rate = live_prices['rates']['XAU'] xag_rate = live_prices['rates']['XAG'] gold_price_per_oz = 1 / xau_rate silver_price_per_oz = 1 / xag_rate print(f"Gold: ${gold_price_per_oz:.2f} per troy oz") print(f"Silver: ${silver_price_per_oz:.2f} per troy oz") conversion = client.convert( from_currency='USD', to_currency='XAU', amount=10000 ) if conversion.get('success'): print(f"$10,000 = {conversion['result']:.4f} troy oz of gold") change = client.change( start_date='2024-01-29', end_date='2024-02-05', base='USD', currencies=['XAU', 'XAG'] ) if change.get('success'): for metal, data in change['rates'].items(): print(f"{metal} change: {data.get('change_pct', 0):.2f}%") usage = client.usage() remaining = usage['usage']['limit'] - usage['usage']['requests'] print(f"API calls remaining: {remaining}") except Exception as e: print(f"Error: {str(e)}") print("Check your API key and network connection") ``` -------------------------------- ### Fetch Carat Prices (Python) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Retrieves Carat prices, optionally for a specific date. Defaults to live rates if no date is provided. Accepts an optional base currency. ```python client.carat(base='USD', date='2024-02-05') ``` -------------------------------- ### Fetch Available Symbols (Python) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Retrieves a list of all available currency symbols supported by the MetalpriceAPI. This function is useful for understanding the range of currencies you can query. ```python client.fetchSymbols() ``` -------------------------------- ### Fetch Available Symbols (Python) Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Retrieves all supported currency and metal symbols from the MetalpriceAPI. The response includes the full name and symbol code for each item. This is useful for understanding available data points. ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Get all available symbols result = client.fetchSymbols() print(result) # Expected output: # { # "success": true, # "symbols": { # "XAU": "Gold", # "XAG": "Silver", # "XPT": "Platinum", # "XPD": "Palladium", # "USD": "United States Dollar", # "EUR": "Euro", # ... # } # } ``` -------------------------------- ### Fetch Live Metal Prices (Python) Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Fetches real-time metal prices. You can specify a base currency and filter for specific metal symbols. If no filters are applied, it defaults to USD and returns all available rates. ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Fetch live prices for specific metals in USD result = client.fetchLive(base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT']) print(result) # Expected output: # { # "success": true, # "base": "USD", # "timestamp": 1707139200, # "rates": { # "XAU": 0.0004951, # Price of 1 USD in troy ounces of gold # "XAG": 0.0431, # Price of 1 USD in troy ounces of silver # "XPD": 0.0010, # Price of 1 USD in troy ounces of palladium # "XPT": 0.0011 # Price of 1 USD in troy ounces of platinum # } # } # Fetch all available rates with EUR as base result = client.fetchLive(base='EUR', currencies=[]) print(result) # Use default USD base with no filtering result = client.fetchLive() print(result) ``` -------------------------------- ### Fetch Available Symbols Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Retrieve all available currency and metal symbols supported by the API, including their full names and symbol codes. ```APIDOC ## Fetch Available Symbols ### Description Retrieve all available currency and metal symbols supported by the API, including their full names and symbol codes. ### Method `fetchSymbols()` ### Endpoint N/A (Method call on client object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Get all available symbols result = client.fetchSymbols() print(result) ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **symbols** (object) - A key-value map of symbols and their names. #### Response Example ```json { "success": true, "symbols": { "XAU": "Gold", "XAG": "Silver", "XPT": "Platinum", "XPD": "Palladium", "USD": "United States Dollar", "EUR": "Euro" } } ``` ``` -------------------------------- ### fetchOHLC(base, currency, date, unit, dateType) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Fetches Open, High, Low, and Close (OHLC) data for a specific metal on a given date. ```APIDOC #### fetchOHLC(base, currency, date, unit, date_type) Retrieves Open, High, Low, and Close (OHLC) data for a specific metal on a given date. - `base` <[string]> Optional. Pass in a base currency, defaults to USD. - `currency` <[string]> Required. Specify currency you would like to get OHLC for. - `date` <[string]> Required. Specify date to get OHLC for specific date using format `YYYY-MM-DD`. - `unit` <[string]> Optional. Pass in a unit, defaults to troy_oz. - `date_type` <[string]> Optional. Pass in a date type, overrides date parameter if passed in. ```python client.fetchOHLC(base='USD', currency='XAU', date='2024-02-05', unit='troy_oz', date_type=None) ``` [Link](https://metalpriceapi.com/documentation#api_ohlc) ``` -------------------------------- ### timeframe(start_date, end_date, base, currencies) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Fetches metal price data for a specified date range. ```APIDOC #### timeframe(start_date, end_date, base, currencies) Retrieves metal price data for a specified timeframe. - `start_date` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`. - `end_date` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`. - `base` <[string]> Optional. Pass in a base currency, defaults to USD. - `currencies` <[List]<[string]>> Optional. Pass in an list of currencies to return values for. ```python 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) ``` -------------------------------- ### carat(base, date) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Fetches Carat prices, optionally for a specific date. ```APIDOC #### carat(base, date) Retrieves Carat prices. - `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) ``` -------------------------------- ### Fetch OHLC Data (Python) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Fetches Open, High, Low, and Close (OHLC) data for a specific metal on a given date. Supports optional base currency, unit, and date type. ```python client.fetchOHLC(base='USD', currency='XAU', date='2024-02-05', unit='troy_oz', date_type=None) ``` -------------------------------- ### Fetch API Usage Information (Python) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Retrieves information about the current API usage. This function is useful for monitoring your API consumption. ```python client.usage() ``` -------------------------------- ### convert(from_currency, to_currency, amount, date) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Converts a given amount from one currency to another, optionally using a historical date. ```APIDOC #### convert(from_currency, to_currency, amount, date) Converts an amount from one currency to another. - `from_currency` <[string]> Optional. Pass in a base currency, defaults to USD. - `to_currency` <[string]> Required. Specify currency you would like to convert to. - `amount` <[number]> Required. The amount to convert. - `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='2024-02-05') ``` [Link](https://metalpriceapi.com/documentation#api_convert) ``` -------------------------------- ### Convert Currencies (Python) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Converts an amount from one currency to another. Supports specifying a date for historical conversions; otherwise, it uses live rates. ```python client.convert(from_currency='USD', to_currency='EUR', amount=100, date='2024-02-05') ``` -------------------------------- ### Check API Usage with MetalPriceAPI Python Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Monitors your API key usage, including the number of requests made and remaining quota based on your subscription plan. This is essential for managing API access and avoiding service interruptions. Requires the API key and metalpriceapi library. ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Check current API usage statistics result = client.usage() print(result) # Use this to monitor rate limits and plan accordingly if result['usage']['requests'] > result['usage']['limit'] * 0.9: print("Warning: Approaching API limit") ``` -------------------------------- ### Convert Between Currencies and Metals Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Convert amounts between different currencies and metals with support for both live and historical rates. ```APIDOC ## Convert Between Currencies and Metals ### Description Convert amounts between different currencies and metals with support for both live and historical rates. ### Method `convert(from_currency, to_currency, amount, date=None)` ### Endpoint N/A (Method call on client object) ### Parameters #### Path Parameters None #### Query Parameters - **from_currency** (string) - Required. The currency or metal symbol to convert from (e.g., 'XAU', 'USD'). - **to_currency** (string) - Required. The currency or metal symbol to convert to (e.g., 'USD', 'EUR'). - **amount** (float) - Required. The amount to convert. - **date** (string) - Optional. The historical date in 'YYYY-MM-DD' format for historical conversions. If omitted, live rates are used. #### Request Body None ### Request Example ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Convert 100 USD to XAU using live rates result = client.convert(from_currency='USD', to_currency='XAU', amount=100) print(result) # Convert 500 EUR to XAG on a historical date result = client.convert(from_currency='EUR', to_currency='XAG', amount=500, date='2024-01-20') print(result) # Convert 1 ounce of XAU to USD on a historical date result = client.convert(from_currency='XAU', to_currency='USD', amount=1, date='2024-02-01') print(result) ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **from** (string) - The currency or metal symbol converted from. - **to** (string) - The currency or metal symbol converted to. - **amount** (float) - The original amount converted. - **date** (string) - The date of the conversion (either live or historical). - **result** (float) - The converted amount. #### Response Example ```json { "success": true, "from": "USD", "to": "XAU", "amount": 100.0, "date": "2024-02-07", "result": 0.04951 } ``` ``` -------------------------------- ### change(start_date, end_date, base, currencies) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Calculates the price change of metals within a given date range. ```APIDOC #### change(start_date, end_date, base, currencies) Calculates the price change of metals within a given timeframe. - `start_date` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`. - `end_date` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`. - `base` <[string]> Optional. Pass in a base currency, defaults to USD. - `currencies` <[List]<[string]>> Optional. Pass in an list of currencies to return values for. ```python 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) ``` -------------------------------- ### Fetch OHLC Data Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Retrieve Open-High-Low-Close price data for a specific metal on a given date, useful for charting and technical analysis. ```APIDOC ## Fetch OHLC Data ### Description Retrieve Open-High-Low-Close price data for a specific metal on a given date, useful for charting and technical analysis. ### Method `fetchOHLC(base, currency, date, unit='troy_oz', date_type=None)` ### Endpoint N/A (Method call on client object) ### Parameters #### Path Parameters None #### Query Parameters - **base** (string) - Required. The base currency (e.g., 'USD', 'EUR'). - **currency** (string) - Required. The metal symbol (e.g., 'XAU', 'XAG'). - **date** (string) - Required. The date in 'YYYY-MM-DD' format. - **unit** (string) - Optional. The unit of measurement for the prices (e.g., 'troy_oz', 'gram'). Defaults to 'troy_oz'. - **date_type** (string) - Optional. Can be 'date' or 'timestamp'. Defaults to 'date'. #### Request Body None ### Request Example ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Fetch OHLC data for gold on a specific date result = client.fetchOHLC( base='USD', currency='XAU', date='2024-02-06', unit='troy_oz', date_type=None ) print(result) # Fetch OHLC for silver with EUR base result = client.fetchOHLC( base='EUR', currency='XAG', date='2024-02-06', unit='troy_oz' ) print(result) ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **base** (string) - The base currency. - **currency** (string) - The metal symbol. - **date** (string) - The date for which OHLC data was retrieved. - **unit** (string) - The unit of measurement for the prices. - **ohlc** (object) - An object containing the open, high, low, and close prices. - **open** (float) - The opening price. - **high** (float) - The highest price. - **low** (float) - The lowest price. - **close** (float) - The closing price. #### Response Example ```json { "success": true, "base": "USD", "currency": "XAU", "date": "2024-02-06", "unit": "troy_oz", "ohlc": { "open": 2019.50, "high": 2025.75, "low": 2015.25, "close": 2022.30 } } ``` ``` -------------------------------- ### Convert Between Currencies and Metals (Python) Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Facilitates conversions between different currencies and precious metals using both live and historical rates. This functionality is essential for financial calculations and portfolio management. ```python from metalpriceapi.client import Client client = Client('your_api_key_here') ``` -------------------------------- ### fetchHistorical(date, base, currencies) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Fetches historical metal prices for a specific date. ```APIDOC #### fetchHistorical(date, base, currencies) Retrieves historical metal prices for a specific date. - `date` <[string]> Required. Pass in a string with format `YYYY-MM-DD` - `base` <[string]> Optional. Pass in a base currency, defaults to USD. - `currencies` <[List]<[string]>> Optional. Pass in an list of currencies to return values for. ```python client.fetchHistorical(date='2024-02-05', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT']) ``` [Link](https://metalpriceapi.com/documentation#api_historical) ``` -------------------------------- ### Fetch Historical Metal Prices (Python) Source: https://github.com/metalpriceapi/metalpriceapi-python/blob/main/README.md Retrieves historical metal prices for a specific date. Requires a date in 'YYYY-MM-DD' format and optionally accepts a base currency and a list of target currencies. ```python client.fetchHistorical(date='2024-02-05', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT']) ``` -------------------------------- ### Fetch OHLC Data (Python) Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Retrieves Open-High-Low-Close (OHLC) price data for a specific metal on a given date and unit. This data is valuable for technical analysis and charting. Optional parameters include base currency and date type. ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Fetch OHLC data for gold on a specific date result = client.fetchOHLC( base='USD', currency='XAU', date='2024-02-06', unit='troy_oz', date_type=None ) print(result) # Expected output: # { # "success": true, # "base": "USD", # "currency": "XAU", # "date": "2024-02-06", # "unit": "troy_oz", # "ohlc": { # "open": 2019.50, # "high": 2025.75, # "low": 2015.25, # "close": 2022.30 # } # } # Fetch OHLC for silver with EUR base result = client.fetchOHLC( base='EUR', currency='XAG', date='2024-02-06', unit='troy_oz' ) print(result) ``` -------------------------------- ### Fetch Historical Metal Prices Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Retrieve metal prices for a specific historical date with optional base currency and metal filtering. ```APIDOC ## Fetch Historical Metal Prices ### Description Retrieve metal prices for a specific historical date with optional base currency and metal filtering. ### Method `fetchHistorical(date, base='USD', currencies=[])` ### Endpoint N/A (Method call on client object) ### Parameters #### Path Parameters None #### Query Parameters - **date** (string) - Required. The historical date in 'YYYY-MM-DD' format. - **base** (string) - Optional. The base currency or metal symbol (e.g., 'USD', 'EUR', 'XAU'). Defaults to 'USD'. - **currencies** (array of strings) - Optional. An array of currency or metal symbols to fetch prices for (e.g., ['XAU', 'XAG']). If empty, all available rates for the date are returned. #### Request Body None ### Request Example ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Fetch historical prices for a specific date result = client.fetchHistorical( date='2024-02-05', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'] ) print(result) # Fetch all metals for a date with GBP as base result = client.fetchHistorical(date='2024-01-15', base='GBP', currencies=[]) print(result) ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **historical** (boolean) - True if historical data was retrieved. - **base** (string) - The base currency or metal symbol used for the rates. - **date** (string) - The requested historical date. - **timestamp** (integer) - The Unix timestamp of the historical rates. - **rates** (object) - A key-value map of currency or metal symbols and their corresponding prices for the specified date. #### Response Example ```json { "success": true, "historical": true, "base": "USD", "date": "2024-02-05", "timestamp": 1707091200, "rates": { "XAU": 0.0004951, "XAG": 0.0431, "XPD": 0.0010, "XPT": 0.0011 } } ``` ``` -------------------------------- ### Fetch Historical Metal Prices (Python) Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Retrieves metal prices for a specific historical date. Similar to live prices, you can set a base currency and filter by metal symbols. This is useful for analyzing past market data. ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Fetch historical prices for a specific date result = client.fetchHistorical( date='2024-02-05', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'] ) print(result) # Expected output: # { # "success": true, # "historical": true, # "base": "USD", # "date": "2024-02-05", # "timestamp": 1707091200, # "rates": { # "XAU": 0.0004951, # "XAG": 0.0431, # "XPD": 0.0010, # "XPT": 0.0011 # } # } # Fetch all metals for a date with GBP as base result = client.fetchHistorical(date='2024-01-15', base='GBP', currencies=[]) print(result) ``` -------------------------------- ### Calculate Price Changes with MetalPriceAPI Python Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Calculates the price change and percentage change for specified metals between two dates. This is valuable for assessing investment performance or market volatility. Requires the API key and metalpriceapi library. ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Calculate price change for metals over a date range result = client.change( start_date='2024-02-05', end_date='2024-02-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'] ) print(result) # Calculate monthly change for all currencies result = client.change( start_date='2024-01-01', end_date='2024-01-31', base='GBP' ) print(result) ``` -------------------------------- ### Fetch Timeframe Data with MetalPriceAPI Python Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Retrieves metal prices across a specified date range to analyze trends and historical patterns. This function is useful for understanding market movements over time. It requires the API key and the metalpriceapi library. ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Fetch prices for a date range result = client.timeframe( start_date='2024-02-05', end_date='2024-02-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'] ) print(result) # Fetch week-long timeframe for all metals result = client.timeframe( start_date='2024-02-01', end_date='2024-02-07', base='EUR', currencies=[] ) print(result) ``` -------------------------------- ### Fetch Gold Carat Prices with MetalPriceAPI Python Source: https://context7.com/metalpriceapi/metalpriceapi-python/llms.txt Retrieves gold prices by carat (e.g., 24K, 22K, 18K) for jewelry pricing and valuation. This function allows fetching current or historical carat prices in different base currencies. Requires the API key and metalpriceapi library. ```python from metalpriceapi.client import Client client = Client('your_api_key_here') # Fetch current carat prices in USD result = client.carat(base='USD') print(result) # Fetch historical carat prices result = client.carat(base='USD', date='2024-02-06') print(result) # Fetch carat prices in EUR result = client.carat(base='EUR') print(result) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.