How to Get Real-Time abrdn Physical Gold Shares ETF (SGOL) Prices Using Python with Metals-API
How to Get Real-Time abrdn Physical Gold Shares ETF (SGOL) Prices Using Python with Metals-API
In the world of finance, having access to real-time market data is crucial for making informed investment decisions. For those interested in precious metals, particularly gold, the Metals-API provides a powerful solution for accessing real-time prices and historical data. In this blog post, we will explore how to utilize the Metals-API to get real-time prices for the abrdn Physical Gold Shares ETF (SGOL) using Python. We will cover the API's capabilities, key features, and provide detailed instructions on how to implement it effectively.
Understanding Metals-API
The Metals-API is a robust JSON API that provides real-time and historical prices for various metals, including gold (XAU), silver (XAG), platinum (XPT), and palladium (XPD). This API is designed for developers looking to integrate precious metals data into their applications, enabling them to build innovative solutions that leverage real-time market insights.
About Gold (XAU)
Gold has long been a symbol of wealth and stability, often serving as a hedge against inflation and economic uncertainty. In recent years, the digital transformation in precious metals has opened new avenues for trading and investment. With the integration of data analytics and technology, traders can now access market insights that were previously unavailable. The Metals-API empowers developers to harness these insights, facilitating innovation in price discovery and enabling the creation of digital asset solutions.
Key Features of Metals-API
The Metals-API offers a variety of endpoints that cater to different data 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 your subscription plan.
- Historical Rates Endpoint: Access historical rates dating back to 2019 by appending a specific date to your API call.
- Bid and Ask Endpoint: Retrieve real-time bid and ask prices for metals, allowing traders to make informed decisions based on current market conditions.
- Convert Endpoint: Convert any amount from one metal to another or to/from USD, facilitating seamless transactions.
- Time-Series Endpoint: Query daily historical rates between two dates, providing insights into market trends over time.
- Fluctuation Endpoint: Track how metal prices fluctuate on a day-to-day basis, helping traders understand market volatility.
- Carat Endpoint: Retrieve gold rates by carat, useful for jewelers and consumers alike.
- Lowest/Highest Price Endpoint: Get the lowest and highest prices for a specified date range, aiding in market analysis.
- Open/High/Low/Close (OHLC) Price Endpoint: Access OHLC data for a specific time period, essential for technical analysis.
- Historical LME Endpoint: Access historical rates for LME symbols dating back to 2008, providing a comprehensive view 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, with all data returned in a structured JSON format.
- News Endpoint: Retrieve the latest news articles related to various metals, keeping you informed about market developments.
Getting Started with Metals-API
To begin using the Metals-API, you will first need to sign up for an account on the Metals-API Website. Once registered, you will receive an API key that you will use to authenticate your requests. The API key should be included in the access_key parameter of your API calls.
Making Your First API Call
Let’s start by making a simple API call to retrieve the latest gold prices. The endpoint for the latest rates is straightforward:
GET https://metals-api.com/api/latest?access_key=YOUR_API_KEY&base=USD&symbols=XAU
In this example, replace YOUR_API_KEY with your actual API key. The response will provide you with the latest gold price in USD.
Understanding API Responses
The response from the latest rates endpoint will look something like this:
{
"success": true,
"timestamp": 1771806303,
"base": "USD",
"date": "2026-02-23",
"rates": {
"XAU": 0.000482
},
"unit": "per troy ounce"
}
Here’s a breakdown of the response fields:
- success: Indicates whether the API call was successful.
- timestamp: The time at which the data was retrieved.
- base: The base currency for the exchange rate (in this case, USD).
- date: The date for which the rates are applicable.
- rates: An object containing the exchange rates for the requested symbols.
- unit: The unit of measurement for the rates (per troy ounce).
Exploring Additional Endpoints
Beyond the latest rates, the Metals-API provides several other endpoints that can enhance your trading strategies. For example, if you want to analyze historical data, you can use the Historical Rates Endpoint:
GET https://metals-api.com/api/historical?access_key=YOUR_API_KEY&date=2026-02-22&symbols=XAU
This call will return the gold price for the specified date. The response will be similar to the latest rates response, but it will include the price for that specific date.
Time-Series Data for Trend Analysis
For traders looking to analyze trends over time, the Time-Series Endpoint is invaluable. You can query for daily historical rates between two dates:
GET https://metals-api.com/api/timeseries?access_key=YOUR_API_KEY&start_date=2026-02-16&end_date=2026-02-23&base=USD&symbols=XAU
The response will provide you with a series of rates for each day in the specified range, allowing for comprehensive trend analysis.
Conversion and Fluctuation Tracking
The Convert Endpoint allows you to convert amounts between different metals or from/to USD. For instance:
GET https://metals-api.com/api/convert?access_key=YOUR_API_KEY&from=USD&to=XAU&amount=1000
This will convert 1000 USD into troy ounces of gold. The response will indicate the conversion rate and the result.
Additionally, the Fluctuation Endpoint can be used to track how prices change over a specific period:
GET https://metals-api.com/api/fluctuation?access_key=YOUR_API_KEY&start_date=2026-02-16&end_date=2026-02-23&base=USD&symbols=XAU
This endpoint will provide insights into the price changes, helping traders make informed decisions based on market volatility.
Advanced Features for Serious Traders
For those who require more detailed analysis, the OHLC (Open/High/Low/Close) Price Endpoint is essential:
GET https://metals-api.com/api/open-high-low-close?access_key=YOUR_API_KEY&date=2026-02-23&symbols=XAU
This will return the open, high, low, and close prices for gold on the specified date, providing critical data for technical analysis.
Security and Best Practices
When working with APIs, security is paramount. Always ensure that your API key is kept confidential and not exposed in public repositories. Implement rate limiting and error handling in your application to manage API usage effectively. Additionally, consider caching responses where appropriate to reduce the number of API calls and improve performance.
Conclusion
The Metals-API is a powerful tool for developers looking to integrate real-time precious metals data into their applications. By leveraging its various endpoints, you can access the latest gold prices, historical data, and perform conversions with ease. Whether you are building a trading platform, a financial analysis tool, or simply seeking to stay informed about market trends, the Metals-API provides the necessary resources to achieve your goals.
For more information, refer to the Metals-API Documentation and explore the Metals-API Supported Symbols to find the data you need. Start integrating real-time metals data into your applications today and unlock the potential of informed trading decisions.