Skip to content

Use An API To Get Aluminum Rates In PHP

If you are looking for an API that gives you aluminum rates in PHP you came to the right place.

In 2020, the global primary aluminum output is expected to reach 65.3 million tonnes. China produced the most, with 37 million tonnes, followed by India, Russia, and Canada. Global demand for aluminum fell somewhat in 2020, owing to COVID-19 and lower pricing in the middle of the year. Prices soon rebounded in the second half of the year, as activity in various regions of the world resumed.

Use An API To Get Aluminum Rates In PHP

Collecting data on aluminum historical rates, fluctuation statistics, and current prices can assist you in determining the optimum time to invest. To gather this data, you’ll need to utilize an API, which is software that links two devices and communicates data between them. When this API is available in PHP, it makes life easier for developers.

What Exactly Is PHP?

PHP is a server-side programming language for developing static, interactive, and web-based applications. The term PHP stands for Hypertext Preprocessor. PHP scripts can only be executed on servers that have the PHP programming language installed. Client computers that access the PHP scripts just require a web browser.

PHP is not used by all APIs. As a consequence, we propose Metals-API, one of the most well-known and comprehensive APIs for precious metals pricing, to assist you in making better investments. This will show you the current and historical metal prices. Price fluctuation data may also be used to investigate price changes. You can choose between USD, Euro, and more than 170 additional currencies.

Use An API To Get Aluminum Rates In PHP

Complete the following steps to receive your one-of-a-kind API key:

  1. Visit www.metals-API.com.
  2. Keep an eye out for the aluminum symbols (ALU) on the website’s list.
  3. Add these metal and currency symbols to the list, then contact the API. You may also choose from a variety of programming languages and rate types, including historical and spot pricing.
  4. Finish by pressing the “Run” button.

The API will display the following:

// set API Endpoint and API key 
$endpoint = 'latest';
$access_key = 'API_KEY';

// Initialize CURL:
$ch = curl_init('https://metals-api.com/api/'.$endpoint.'?access_key='.$access_key.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Store the data:
$json = curl_exec($ch);
curl_close($ch);

// Decode JSON response:
$exchangeRates = json_decode($json, true);

// Access the exchange rate values, e.g. GBP:
echo $exchangeRates['rates']['GBP'];

Why Metals-API

Metals-API is visited by a large number of developers, small businesses, and large companies each day. Over 500 businesses, including Barrick Gold, Chainlink, and Glencore, use this API. This application allows them to quickly and easily obtain current global market prices for any metal.

Metals-API is the most reliable source for real-time precious metals rates since it gets data from around 15 trusted data sources, such as financial institutions, every minute. Many programming languages, including JSON, Python, and PHP, may be used to build real-time apps and software with data.

Published inAppsTechnology
%d bloggers like this: