PHP code example of metalpriceapi / metalpriceapi-php

1. Go to this page and download the library: Download metalpriceapi/metalpriceapi-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

metalpriceapi / metalpriceapi-php example snippets


use MetalpriceAPI\Client;

$client = new Client('SET_YOUR_API_KEY_HERE');
$result = $client->fetchLive('USD', ['XAU', 'XAG', 'XPD', 'XPT']);

use MetalpriceAPI\Client;

// Default (US)
$client = new Client('SET_YOUR_API_KEY_HERE');

// Europe
$client = new Client('SET_YOUR_API_KEY_HERE', Client::BASE_URL_EU);

$client = new Client('SET_YOUR_API_KEY_HERE');

// Switch to EU server
$client->setServer('eu');

// Switch back to US server
$client->setServer('us');

$client->fetchSymbols();

$client->fetchLive('USD', ['XAU', 'XAG', 'XPD', 'XPT'], 'troy_oz', null, null);

$client->fetchHistorical('2024-02-05', 'USD', ['XAU', 'XAG', 'XPD', 'XPT'], 'troy_oz');

$client->hourly('USD', 'XAU', 'troy_oz', '2025-11-03', '2025-11-03', null, null);

$client->ohlc('USD', 'XAU', '2024-02-06', 'troy_oz', null);

$client->convert('USD', 'EUR', 100, '2024-02-05', null);

$client->timeframe('2024-02-05', '2024-02-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT'], 'troy_oz');

$client->change('2024-02-05', '2024-02-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT'], null);

$client->carat('USD', 'XAU', '2024-02-06');

$client->usage();

$ composer