Using the API to Get B
Using the API to Get Historical Prices for XAU (Gold) with Metals-API
In the ever-evolving landscape of financial technology, the ability to access real-time and historical data is paramount for developers and businesses alike. One such powerful tool is the Metals-API, which provides comprehensive access to metal prices, including XAU (Gold), XAG (Silver), XPT (Platinum), and XPD (Palladium). This blog post will delve into the capabilities of the Metals-API, focusing on how to retrieve historical prices for XAU, and explore the innovative features that empower developers to create next-generation applications.
Metals-API Information
The Metals-API is a robust JSON API that offers real-time and historical pricing data for various metals. It is designed to cater to the needs of developers, financial analysts, and businesses looking to integrate metal pricing data into their applications. With its user-friendly interface and extensive documentation, the Metals-API allows users to access a wealth of information that can drive decision-making and enhance financial strategies.
API Description
At its core, the Metals-API provides a suite of endpoints that deliver real-time and historical data on metal prices. The API is built on modern technologies, ensuring high availability and low latency, which is crucial for applications that require timely data. The transformative potential of the Metals-API lies in its ability to provide developers with the tools needed to build applications that can analyze trends, forecast prices, and make informed trading decisions.
For more detailed information, developers can refer to the Metals-API Documentation, which outlines the various endpoints, parameters, and response formats.
Key Features and Endpoints
The Metals-API boasts a variety of endpoints, each designed to serve specific needs. Here are some of the key features:
- Latest Rates Endpoint: This endpoint provides real-time exchange rate data for metals, updated every 60 minutes, 10 minutes, or even more frequently, depending on the subscription plan. This feature is essential for applications that require up-to-the-minute pricing information.
- Historical Rates Endpoint: Users can access historical rates for XAU dating back to 2019. By appending a specific date to the API call, developers can retrieve past prices, which is invaluable for trend analysis and forecasting.
- Bid and Ask Endpoint: This powerful feature allows users to retrieve real-time bid and ask prices for metals, providing insights into market dynamics and helping traders make informed decisions.
- Convert Endpoint: The conversion endpoint enables users to convert any amount from one metal to another or to/from USD, facilitating seamless transactions and calculations.
- Time-Series Endpoint: This endpoint allows users to query daily historical rates between two dates, making it easier to analyze price movements over specific periods.
- Fluctuation Endpoint: Users can track how metal prices fluctuate on a day-to-day basis, providing insights into market volatility and trends.
- Carat Endpoint: This feature allows users to retrieve information about gold rates by carat, which is particularly useful for jewelers and consumers interested in specific gold qualities.
- Lowest/Highest Price Endpoint: Developers can query the API to get the lowest and highest prices for a specified date, which is crucial for understanding market extremes.
- Open/High/Low/Close (OHLC) Price Endpoint: This endpoint provides open, high, low, and close prices for a specific date, allowing for detailed market analysis.
- Historical LME Endpoint: This endpoint provides access to historical rates for LME symbols dating back to 2008, which is essential for users interested in long-term trends.
- API Key: Each user is assigned a unique API key that must be included in API requests to authenticate and authorize access.
- API Response: The Metals-API returns exchange rates relative to USD by default, ensuring consistency and ease of use.
- Supported Symbols Endpoint: This endpoint provides a constantly updated list of all available currencies and metals, ensuring users have access to the latest information.
- News Endpoint: Users can retrieve the latest news articles related to various metals, keeping them 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 the structure of API responses is crucial for effective integration. Below are examples of responses from various endpoints:
Latest Rates Endpoint
Get real-time exchange rates for all available metals.
{
"success": true,
"timestamp": 1769386990,
"base": "USD",
"date": "2026-01-26",
"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"
}
Historical Rates Endpoint
Access historical exchange rates for any date since 1999.
{
"success": true,
"timestamp": 1769300590,
"base": "USD",
"date": "2026-01-25",
"rates": {
"XAU": 0.000485,
"XAG": 0.03825,
"XPT": 0.000915,
"XPD": 0.000748
},
"unit": "per troy ounce"
}
Time-series Endpoint
Get exchange rates for a specific time period.
{
"success": true,
"timeseries": true,
"start_date": "2026-01-19",
"end_date": "2026-01-26",
"base": "USD",
"rates": {
"2026-01-19": {
"XAU": 0.000485,
"XAG": 0.03825,
"XPT": 0.000915
},
"2026-01-21": {
"XAU": 0.000483,
"XAG": 0.0382,
"XPT": 0.000913
},
"2026-01-26": {
"XAU": 0.000482,
"XAG": 0.03815,
"XPT": 0.000912
}
},
"unit": "per troy ounce"
}
Convert Endpoint
Convert any amount from one metal to another or to/from USD.
{
"success": true,
"query": {
"from": "USD",
"to": "XAU",
"amount": 1000
},
"info": {
"timestamp": 1769386990,
"rate": 0.000482
},
"result": 0.482,
"unit": "troy ounces"
}
Fluctuation Endpoint
Track rate fluctuations between two dates.
{
"success": true,
"fluctuation": true,
"start_date": "2026-01-19",
"end_date": "2026-01-26",
"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"
}
OHLC (Open/High/Low/Close) Endpoint
Get OHLC data for a specific time period.
{
"success": true,
"timestamp": 1769386990,
"base": "USD",
"date": "2026-01-26",
"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"
}
Bid/Ask Endpoint
Get current bid and ask prices for metals.
{
"success": true,
"timestamp": 1769386990,
"base": "USD",
"date": "2026-01-26",
"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"
}
Conclusion
The Metals-API is an invaluable resource for developers seeking to integrate real-time and historical metal pricing data into their applications. With its extensive range of endpoints, including the ability to retrieve historical prices for XAU, the API empowers users to make informed decisions based on accurate and timely information. By leveraging the capabilities of the Metals-API, developers can create innovative applications that analyze market trends, forecast prices, and enhance trading strategies.
For further exploration of the API's capabilities, developers are encouraged to visit the Metals-API Documentation and familiarize themselves with the various endpoints and their functionalities. Additionally, the Metals-API Supported Symbols page provides a comprehensive list of available symbols, ensuring users have access to the latest information.
In a world where data drives decisions, the Metals-API stands out as a powerful tool for accessing and utilizing metal pricing data effectively. Whether you are a developer, trader, or analyst, the Metals-API offers the resources needed to stay ahead in the dynamic market of precious metals.