Official PHP client for the Metals-API.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/metals-api/sdk

dev-master 2026-02-11 15:16 UTC

This package is not auto-updated.

Last update: 2026-02-11 18:34:44 UTC


README

Official PHP client for the Metals-API.

Installation

composer require metals-api/sdk

Usage

<?php

require 'vendor/autoload.php';

use MetalsApi\MetalsClient;

$client = new MetalsClient('YOUR_ACCESS_KEY');

$response = $client->getLatest([
    'base'    => 'USD',
    'symbols' => 'XAU,XAG,XPT'
]);

print_r($response);

Methods

// Latest rates
$client->getLatest([
  'base'    => 'USD',
  'symbols' => 'XAU,XAG,XPT'
]);

// Historical (YYYY-MM-DD)
$client->getHistorical('2024-05-15', [
  'base'    => 'USD',
  'symbols' => 'XAU,XAG'
]);

// Time-series
$client->getTimeSeries([
  'start_date' => '2024-01-01',
  'end_date'   => '2024-01-31',
  'base'       => 'USD',
  'symbols'    => 'XAU'
]);

// Fluctuation
$client->getFluctuation([
  'start_date' => '2024-01-01',
  'end_date'   => '2024-01-31',
  'base'       => 'USD',
  'symbols'    => 'XAU,XAG'
]);

// Convert
$client->convert([
  'from'   => 'USD',
  'to'     => 'XAU',
  'amount' => 100
]);

// Symbols
$client->getSymbols();

// Seasonality (cuando exista el endpoint)
$client->getSeasonality([
  'symbol'   => 'XAU',
  'group_by' => 'month',
  'years'    => 5
]);

Error handling

use MetalsApi\MetalsApiException;
use MetalsApi\MetalsClient;

$client = new MetalsClient('YOUR_ACCESS_KEY');

try {
    $response = $client->getLatest(['base' => 'USD']);
} catch (MetalsApiException $e) {
    echo $e->getMessage();
    echo $e->getStatusCode();
    var_dump($e->getRaw());
}