PHPackages                             metalpriceapi/metalpriceapi-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. metalpriceapi/metalpriceapi-php

ActiveLibrary[API Development](/categories/api)

metalpriceapi/metalpriceapi-php
===============================

Official PHP wrapper for MetalpriceAPI.com - Metal price API and foreign exchange rate API

1.0.0(4mo ago)04MITPHPPHP &gt;=7.4

Since Feb 24Pushed 4mo agoCompare

[ Source](https://github.com/metalpriceapi/metalpriceapi-php)[ Packagist](https://packagist.org/packages/metalpriceapi/metalpriceapi-php)[ Docs](https://metalpriceapi.com)[ RSS](/packages/metalpriceapi-metalpriceapi-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

metalpriceapi
=============

[](#metalpriceapi)

metalpriceapi is the official PHP wrapper for MetalpriceAPI.com. This allows you to quickly integrate our metal price API and foreign exchange rate API into your application. Check  documentation for more information.

Installation
------------

[](#installation)

#### Composer

[](#composer)

```
$ composer require metalpriceapi/metalpriceapi-php

```

---

Usage
-----

[](#usage)

```
use MetalpriceAPI\Client;

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

---

Server Regions
--------------

[](#server-regions)

MetalpriceAPI provides two regional endpoints. Choose the one closest to your servers for optimal performance.

RegionBase URLUnited States (default)`https://api.metalpriceapi.com/v1`Europe`https://api-eu.metalpriceapi.com/v1````
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);
```

---

setServer
---------

[](#setserver)

You can switch server regions at runtime using the `setServer` method:

```
$client = new Client('SET_YOUR_API_KEY_HERE');

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

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

---

Documentation
-------------

[](#documentation)

#### fetchSymbols()

[](#fetchsymbols)

```
$client->fetchSymbols();
```

[Link](https://metalpriceapi.com/documentation#api_symbol)

---

#### fetchLive($base, $currencies, $unit, $purity, $math)

[](#fetchlivebase-currencies-unit-purity-math)

- `$base` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a base currency, defaults to USD.
- `$currencies` &lt;[array](https://www.php.net/manual/en/language.types.array.php "Array")&lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt;&gt; Optional. Pass in an array of currencies to return values for.
- `$unit` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`).
- `$purity` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a purity level for metal prices.
- `$math` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a math expression to apply to the rates.

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

[Link](https://metalpriceapi.com/documentation#api_realtime)

---

#### fetchHistorical($date, $base, $currencies, $unit)

[](#fetchhistoricaldate-base-currencies-unit)

- `$date` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Pass in a string with format `YYYY-MM-DD`
- `$base` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a base currency, defaults to USD.
- `$currencies` &lt;[array](https://www.php.net/manual/en/language.types.array.php "Array")&lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt;&gt; Optional. Pass in an array of currencies to return values for.
- `$unit` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`).

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

[Link](https://metalpriceapi.com/documentation#api_historical)

---

#### hourly($base, $currency, $unit, $startDate, $endDate, $math, $dateType)

[](#hourlybase-currency-unit-startdate-enddate-math-datetype)

- `$base` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a base currency, defaults to USD.
- `$currency` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Specify currency you would like to get hourly rates for.
- `$unit` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`).
- `$startDate` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Specify the start date using the format `YYYY-MM-DD`.
- `$endDate` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Specify the end date using the format `YYYY-MM-DD`.
- `$math` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a math expression to apply to the rates.
- `$dateType` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a date type, overrides date parameters if passed in.

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

[Link](https://metalpriceapi.com/documentation#api_hourly)

---

#### ohlc($base, $currency, $date, $unit, $dateType)

[](#ohlcbase-currency-date-unit-datetype)

- `$base` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a base currency, defaults to USD.
- `$currency` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Specify currency you would like to get OHLC for.
- `$date` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Specify date to get OHLC for specific date using format `YYYY-MM-DD`.
- `$unit` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a unit, defaults to troy\_oz.
- `$dateType` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a date type, overrides date parameter if passed in.

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

[Link](https://metalpriceapi.com/documentation#api_ohlc)

---

#### convert($from, $to, $amount, $date, $unit)

[](#convertfrom-to-amount-date-unit)

- `$from` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a base currency, defaults to USD.
- `$to` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Specify currency you would like to convert to.
- `$amount` &lt;[number](https://www.php.net/manual/en/language.types.float.php "Number")&gt; Required. The amount to convert.
- `$date` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Specify date to use historical midpoint value for conversion with format `YYYY-MM-DD`. Otherwise, it will use live exchange rate date if value not passed in.
- `$unit` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`).

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

[Link](https://metalpriceapi.com/documentation#api_convert)

---

#### timeframe($startDate, $endDate, $base, $currencies, $unit)

[](#timeframestartdate-enddate-base-currencies-unit)

- `$startDate` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`.
- `$endDate` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`.
- `$base` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a base currency, defaults to USD.
- `$currencies` &lt;[array](https://www.php.net/manual/en/language.types.array.php "Array")&lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt;&gt; Optional. Pass in an array of currencies to return values for.
- `$unit` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`).

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

[Link](https://metalpriceapi.com/documentation#api_timeframe)

---

#### change($startDate, $endDate, $base, $currencies, $dateType)

[](#changestartdate-enddate-base-currencies-datetype)

- `$startDate` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`.
- `$endDate` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`.
- `$base` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a base currency, defaults to USD.
- `$currencies` &lt;[array](https://www.php.net/manual/en/language.types.array.php "Array")&lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt;&gt; Optional. Pass in an array of currencies to return values for.
- `$dateType` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a date type, overrides date parameters if passed in.

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

[Link](https://metalpriceapi.com/documentation#api_change)

---

#### carat($base, $currency, $date)

[](#caratbase-currency-date)

- `$base` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a base currency, defaults to USD.
- `$currency` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Pass in a metal code to get carat prices for (defaults to XAU).
- `$date` &lt;[string](https://www.php.net/manual/en/language.types.string.php "String")&gt; Optional. Specify date to get Carat for specific date using format `YYYY-MM-DD`. If not specified, uses live rates.

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

[Link](https://metalpriceapi.com/documentation#api_carat)

---

#### usage()

[](#usage-1)

```
$client->usage();
```

[Link](https://metalpriceapi.com/documentation#api_usage)

---

**[Official documentation](https://metalpriceapi.com/documentation)**

---

FAQ
---

[](#faq)

- How do I get an API Key?

    Free API Keys are available [here](https://metalpriceapi.com).
- I want more information

    Checkout our FAQs [here](https://metalpriceapi.com/faq).

Support
-------

[](#support)

For support, get in touch using [this form](https://metalpriceapi.com/contact).

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance77

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

127d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/049f038cc60758bf4273b2e606195ed035e32a44a57c82a673f23f5584d345cb?d=identicon)[metalpriceapi-user](/maintainers/metalpriceapi-user)

---

Top Contributors

[![metalpriceapi-user](https://avatars.githubusercontent.com/u/85348809?v=4)](https://github.com/metalpriceapi-user "metalpriceapi-user (1 commits)")

---

Tags

apiexchangeratespriceforexgoldsilvermetalplatinumpalladium

### Embed Badge

![Health badge](/badges/metalpriceapi-metalpriceapi-php/health.svg)

```
[![Health](https://phpackages.com/badges/metalpriceapi-metalpriceapi-php/health.svg)](https://phpackages.com/packages/metalpriceapi-metalpriceapi-php)
```

###  Alternatives

[maciej-sz/nbp-php

API for accessing Polish National Bank (NBP - Narodowy Bank Polski) currency and commodities exchange rates

1447.4k1](/packages/maciej-sz-nbp-php)[oneforge/forexquotes

Library to fetch and parse realtime Forex quotes and convert currencies

7312.8k1](/packages/oneforge-forexquotes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
