Using this API to retrieve
Introduction
In the fast-paced world of finance and commodities trading, having access to real-time and historical data is crucial for making informed decisions. One of the most powerful tools available to developers today is the Metals-API. This API provides comprehensive access to metals data, including historical prices, current rates, and various conversion functionalities. In this blog post, we will explore how to retrieve historical prices for metals, specifically focusing on the symbol XAU (Gold), and delve into the innovative capabilities of the Metals-API that empower developers to create next-generation applications.
Metals-API Information
API Description
The Metals-API is a robust and versatile API designed to provide developers with real-time and historical data on various metals. It supports a wide range of functionalities, including retrieving the latest rates, historical prices, bid and ask prices, and much more. The API is built with a focus on innovation and technological advancement, allowing developers to harness the transformative potential of real-time metals data. With the Metals-API, developers can build applications that require accurate and timely information, enabling better decision-making in trading, investment, and financial analysis.
Key Features and Endpoints
The Metals-API offers a variety of endpoints that cater to different data retrieval needs. Here are some of the key features:
- Latest Rates Endpoint: Depending on your subscription plan, this endpoint returns real-time exchange rate data updated every 60 minutes, every 10 minutes, or even more frequently. This feature is essential for applications that require up-to-the-minute pricing information.
- Historical Rates Endpoint: This endpoint allows you to access historical rates for most currencies dating back to 2019. By appending a specific date to your API request, you can retrieve historical prices for metals, which is invaluable for trend analysis and forecasting.
- Bid And Ask Endpoint: This powerful feature enables you to retrieve real-time bid and ask prices for metals, providing insights into market conditions and helping traders make informed decisions.
- Convert Endpoint: The Metals-API includes a currency conversion endpoint, allowing you to convert any amount from one metal to another or to/from USD. This is particularly useful for applications that require multi-currency support.
- Time-Series Endpoint: This endpoint allows you to query the API for daily historical rates between two dates of your choice, facilitating in-depth analysis of price movements over time.
- Fluctuation Endpoint: With this endpoint, you can retrieve information about how currencies fluctuate on a day-to-day basis, providing insights into market volatility.
- Carat Endpoint: This feature allows you to retrieve information about Gold rates by Carat, which is essential for jewelers and those in the luxury goods market.
- Lowest/Highest Price Endpoint: This endpoint enables you to query the API to get the lowest and highest prices for a specified date, helping traders identify market extremes.
- Open/High/Low/Close (OHLC) Price Endpoint: This endpoint provides open, high, low, and close prices for a specific date, which is crucial for technical analysis.
- Historical LME Endpoint: Access historical rates for LME symbols dating back to 2008, allowing for comprehensive analysis of market trends.
- API Key: Your unique API key is required to access the API, ensuring secure and authorized usage.
- API Response: The API delivers exchange rates relative to USD by default, with all data returned in a structured JSON format, making it easy to integrate into applications.
- Available Endpoints: The Metals-API comes with 14 different endpoints, each providing unique functionalities to meet diverse data needs.
- Supported Symbols Endpoint: This endpoint returns a constantly updated list of all available currencies, ensuring you have access to the latest symbols.
- News Endpoint: Retrieve the latest news articles related to various metals, keeping you informed about market developments.
List of Symbols
The Metals-API provides access to a comprehensive range of metal symbols. For a complete list of all supported symbols and their specifications, refer to the Metals-API Supported Symbols page.
API Endpoint Examples and Responses
Understanding how to interact with the Metals-API is crucial for developers looking to integrate its functionalities into their applications. Below, we provide detailed examples of various endpoints, including their responses and explanations of each field.
Latest Rates Endpoint
The Latest Rates Endpoint allows you to get real-time exchange rates for all available metals. Here’s an example response:
{
"success": true,
"timestamp": 1771373739,
"base": "USD",
"date": "2026-02-18",
"rates": {
"XAU": 0.000482,
"XAG": 0.03815,
"XPT": 0.000912,
"XPD": 0.000744,
"XCU": 0.294118,
"XAL": 0.434783,
"XNI": 0.142857,
"XZN": 0.344828
},
"unit": "per troy ounce"
}
In this response:
- success: Indicates whether the API request was successful.
- timestamp: The time at which the data was retrieved.
- base: The base currency for the exchange rates (USD in this case).
- date: The date for which the rates are applicable.
- rates: An object containing the exchange rates for various metals, with symbols as keys.
- unit: The unit of measurement for the rates (per troy ounce).
Historical Rates Endpoint
The Historical Rates Endpoint allows you to access historical exchange rates for any date since 1999. Here’s an example response:
{
"success": true,
"timestamp": 1771287339,
"base": "USD",
"date": "2026-02-17",
"rates": {
"XAU": 0.000485,
"XAG": 0.03825,
"XPT": 0.000915,
"XPD": 0.000748
},
"unit": "per troy ounce"
}
In this response:
- success: Indicates whether the API request was successful.
- timestamp: The time at which the data was retrieved.
- base: The base currency for the exchange rates (USD).
- date: The specific date for which the historical rates are applicable.
- rates: An object containing the historical exchange rates for various metals.
- unit: The unit of measurement for the rates (per troy ounce).
Time-Series Endpoint
The Time-Series Endpoint allows you to get exchange rates for a specific time period. Here’s an example response:
{
"success": true,
"timeseries": true,
"start_date": "2026-02-11",
"end_date": "2026-02-18",
"base": "USD",
"rates": {
"2026-02-11": {
"XAU": 0.000485,
"XAG": 0.03825,
"XPT": 0.000915
},
"2026-02-13": {
"XAU": 0.000483,
"XAG": 0.0382,
"XPT": 0.000913
},
"2026-02-18": {
"XAU": 0.000482,
"XAG": 0.03815,
"XPT": 0.000912
}
},
"unit": "per troy ounce"
}
In this response:
- success: Indicates whether the API request was successful.
- timeseries: Indicates that the response contains time-series data.
- start_date: The start date for the time series.
- end_date: The end date for the time series.
- base: The base currency for the exchange rates (USD).
- rates: An object containing the exchange rates for various dates within the specified range.
- unit: The unit of measurement for the rates (per troy ounce).
Convert Endpoint
The Convert Endpoint allows you to convert any amount from one metal to another or to/from USD. Here’s an example response:
{
"success": true,
"query": {
"from": "USD",
"to": "XAU",
"amount": 1000
},
"info": {
"timestamp": 1771373739,
"rate": 0.000482
},
"result": 0.482,
"unit": "troy ounces"
}
In this response:
- success: Indicates whether the API request was successful.
- query: An object containing the parameters of the conversion request.
- info: Contains additional information about the conversion, including the timestamp and the conversion rate.
- result: The result of the conversion, showing how much of the target metal you receive.
- unit: The unit of measurement for the result (troy ounces).
Fluctuation Endpoint
The Fluctuation Endpoint allows you to track rate fluctuations between two dates. Here’s an example response:
{
"success": true,
"fluctuation": true,
"start_date": "2026-02-11",
"end_date": "2026-02-18",
"base": "USD",
"rates": {
"XAU": {
"start_rate": 0.000485,
"end_rate": 0.000482,
"change": -3.0e-6,
"change_pct": -0.62
},
"XAG": {
"start_rate": 0.03825,
"end_rate": 0.03815,
"change": -0.0001,
"change_pct": -0.26
},
"XPT": {
"start_rate": 0.000915,
"end_rate": 0.000912,
"change": -3.0e-6,
"change_pct": -0.33
}
},
"unit": "per troy ounce"
}
In this response:
- success: Indicates whether the API request was successful.
- fluctuation: Indicates that the response contains fluctuation data.
- start_date: The start date for the fluctuation tracking.
- end_date: The end date for the fluctuation tracking.
- base: The base currency for the exchange rates (USD).
- rates: An object containing the fluctuation details for various metals, including start and end rates, change in value, and percentage change.
- unit: The unit of measurement for the rates (per troy ounce).
OHLC (Open/High/Low/Close) Price Endpoint
The OHLC Price Endpoint provides open, high, low, and close prices for a specific date. Here’s an example response:
{
"success": true,
"timestamp": 1771373739,
"base": "USD",
"date": "2026-02-18",
"rates": {
"XAU": {
"open": 0.000485,
"high": 0.000487,
"low": 0.000481,
"close": 0.000482
},
"XAG": {
"open": 0.03825,
"high": 0.0383,
"low": 0.0381,
"close": 0.03815
},
"XPT": {
"open": 0.000915,
"high": 0.000918,
"low": 0.00091,
"close": 0.000912
}
},
"unit": "per troy ounce"
}
In this response:
- success: Indicates whether the API request was successful.
- timestamp: The time at which the data was retrieved.
- base: The base currency for the exchange rates (USD).
- date: The specific date for which the OHLC data is applicable.
- rates: An object containing the open, high, low, and close prices for various metals.
- unit: The unit of measurement for the rates (per troy ounce).
Bid/Ask Endpoint
The Bid/Ask Endpoint allows you to get current bid and ask prices for metals. Here’s an example response:
{
"success": true,
"timestamp": 1771373739,
"base": "USD",
"date": "2026-02-18",
"rates": {
"XAU": {
"bid": 0.000481,
"ask": 0.000483,
"spread": 2.0e-6
},
"XAG": {
"bid": 0.0381,
"ask": 0.0382,
"spread": 0.0001
},
"XPT": {
"bid": 0.000911,
"ask": 0.000913,
"spread": 2.0e-6
}
},
"unit": "per troy ounce"
}
In this response:
- success: Indicates whether the API request was successful.
- timestamp: The time at which the data was retrieved.
- base: The base currency for the exchange rates (USD).
- date: The date for which the bid and ask prices are applicable.
- rates: An object containing the bid and ask prices for various metals, along with the spread.
- unit: The unit of measurement for the rates (per troy ounce).
Conclusion
The Metals-API is an invaluable resource for developers looking to integrate real-time and historical metals data into their applications. With its extensive range of endpoints, including the ability to retrieve historical prices for metals like XAU, developers can create powerful tools for financial analysis, trading, and investment. By leveraging the capabilities of the Metals-API, developers can build applications that not only provide accurate data but also enhance user experience through innovative features.
For more information on how to get started with the Metals-API, refer to the Metals-API Documentation. To explore the full list of supported symbols, visit the Metals-API Supported Symbols page. With the right tools and knowledge, you can harness the power of metals data to drive your applications forward.