Silver (Ag) is a white shiny metal that is appreciated for its ornamental beauty and electrical conductivity. Along with gold and the platinum-group metals, is considered a valuable metal. Silver has traditionally been employed in the production of coins, ornaments, and jewelry due to its relative rarity, beautiful white color, malleability, ductility, and resistance to air oxidation.
Despite being the second most valuable metal in history, silver is one of the most stable and usable metals on the market. This can serve two purposes: as a wing, similar to gold, or for various sorts of tools, double its worth. Worldwide, Mexico is the country that creates the most silver. In 2020, it produced 178.1 million ounces. It was followed by Peru with 109.7 and China with 108.6.
To get silver prices in real-time or historical rates, you can use an API. This is a collection of definitions and protocols used to create and integrate application software, allowing communication between two software applications via a set of rules.
How To Get An API?
To obtain this information, we propose Metals-API, a free API that provides reliable and timely data on any precious metal in whatever currency you want.
The data on the free plan is refreshed every hour and has an accuracy of 2 decimal points. You will additionally receive 50 API calls each month in this scenario. When you purchase an annual package, you will receive additional API calls and data per minute.
Metals-API gives you the information in Python language for you to use how ever you want.
Python
Python is a high-level general-purpose programming language that is interpreted.
Its design concept prioritizes code readability by employing substantial indentation. Its language features and object-oriented approach are designed to assist programmers in writing clear, logical code for both small and large-scale projects.
Is frequently used in website and software development, as well as task automation, data analysis, and data visualization. Python has been used by many non-programmers, such as accountants and scientists, for a range of typical activities, such as financial planning, due to its relative simplicity of learning.
Silver Example using Python
import requests
base_currency = ‘USD’
symbol = ‘XAG’
endpoint = ‘latest’
access_key = ‘API_KEY’
resp = requests.get(
‘https://metals-api.com/api/’+endpoint+’?access_key=’+access_key+’&base=’+base_currency+’&symbols=’+symbol)
if resp.status_code != 200:
# This means something went wrong.
raise ApiError(‘GET /’+endpoint+’/ {}’.format(resp.status_code))
print(resp.json())
How Does It Work?
To get the data, you must first register on the website, acquire an API key, and then choose the required currency and metal. That’s all there is to it, and you are free to utilize the API any way you see appropriate.
Metals-API collects data from over 15 trustworthy data sources every minute. Among them are banks and financial data suppliers. As a consequence, you will obtain extremely accurate pricing. Metals-API displays the current market value of the world’s most valuable metals, which include gold, silver, aluminum, platinum, and palladium. The data from the website may be used in a variety of locations, including spreadsheets, other websites, and mobile apps.
Also published on Medium.