PHPackages                             tetthys/crypto-price - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tetthys/crypto-price

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tetthys/crypto-price
====================

Ultra-light crypto price service (USD spot + converters) for PHP 8.3+.

0.0.1(8mo ago)035MITPHPPHP ^8.3

Since Oct 19Pushed 8mo agoCompare

[ Source](https://github.com/tetthys/crypto-price)[ Packagist](https://packagist.org/packages/tetthys/crypto-price)[ RSS](/packages/tetthys-crypto-price/feed)WikiDiscussions dev Synced today

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

tetthys/crypto-price
====================

[](#tetthyscrypto-price)

> Lightweight, framework-agnostic crypto price utility for PHP 8.3+.
> Provides simple USD spot price access, crypto-to-USD conversion, and scale-aware math using BCMath.

---

📦 Installation
--------------

[](#-installation)

```
composer require tetthys/crypto-price
```

Requires **PHP 8.3+** and the **bcmath** extension.

---

🚀 Quick Example
---------------

[](#-quick-example)

```
use Tetthys\CryptoPrice\Providers\CallableCryptoPriceProvider;
use Tetthys\CryptoPrice\Services\CryptoPriceService;

$provider = new CallableCryptoPriceProvider(
    fn(string $symbol) => match (strtoupper($symbol)) {
        'BTC' => '98765.4321',
        'ETH' => '3456.78',
        'XMR' => '150.50',
        default => throw new RuntimeException("Unknown symbol: {$symbol}")
    }
);

$service = new CryptoPriceService($provider);

echo $service->usd('BTC'); // "98765.4321"
echo $service->cryptoToUsd('0.015', 'BTC'); // "1481.48"
echo $service->usdToCrypto('1000', 'BTC');  // "0.01012345"
```

---

🧩 Core Concepts
---------------

[](#-core-concepts)

### `CryptoPriceProviderInterface`

[](#cryptopriceproviderinterface)

Defines a source that returns USD spot price per crypto symbol.

```
public function getUsdPrice(string $symbol): string;
```

Example:

- `getUsdPrice('BTC')` → `"98765.4321"`
- `getUsdPrice('ETH')` → `"3456.78"`

---

### `CryptoPriceService`

[](#cryptopriceservice)

A high-level service that performs conversions and handles decimal precision per asset.

```
$service = new CryptoPriceService($provider);

$usd  = $service->cryptoToUsd('0.005', 'BTC'); // "493.82"
$btc  = $service->usdToCrypto('100', 'BTC');   // "0.0010132"
$spot = $service->usd('BTC');                  // "98765.4321"
```

All math uses **BCMath** to ensure fixed-scale precision.

---

### `CryptoScale`

[](#cryptoscale)

A static mapping of default decimal scales per symbol:

SymbolDefault scaleBTC8LTC8XMR12ETH8USDT6Use `CryptoScale::get('BTC')` to retrieve the default scale.

---

### `CallableCryptoPriceProvider`

[](#callablecryptopriceprovider)

A minimal provider that wraps a closure. Perfect for tests or static pricing environments.

```
$provider = new CallableCryptoPriceProvider(
    fn(string $symbol) => ['BTC' => '98765.43', 'ETH' => '3456.78'][$symbol] ?? '0'
);
```

---

⚙️ Integrating with Laravel
---------------------------

[](#️-integrating-with-laravel)

You can easily wire this package into Laravel using a small provider:

```
use App\Support\CryptoPrice\CoinMarketCapProvider;
use Tetthys\CryptoPrice\Services\CryptoPriceService;

$provider = new CoinMarketCapProvider(apiKey: env('COINMARKETCAP_API_KEY'));
$service  = new CryptoPriceService($provider);

echo $service->cryptoToUsd('0.5', 'ETH');
```

or register both in a custom `CryptoPriceServiceProvider`:

```
$this->app->singleton(CryptoPriceProviderInterface::class, fn () =>
    new CoinMarketCapProvider(env('COINMARKETCAP_API_KEY'))
);

$this->app->bind(CryptoPriceService::class, fn ($app) =>
    new CryptoPriceService($app->make(CryptoPriceProviderInterface::class))
);
```

---

🧪 Testing with a Mock Provider
------------------------------

[](#-testing-with-a-mock-provider)

```
use Tetthys\CryptoPrice\Providers\CallableCryptoPriceProvider;
use Tetthys\CryptoPrice\Services\CryptoPriceService;

$mock = new CallableCryptoPriceProvider(fn($s) => match ($s) {
    'BTC' => '10000', 'ETH' => '1000', default => '1'
});

$svc = new CryptoPriceService($mock);
expect($svc->cryptoToUsd('0.5', 'BTC'))->toBe('5000.00');
```

---

🪪 License
---------

[](#-license)

MIT © Tetthys Labs

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance59

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

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

257d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/115064626?v=4)[tetthys](/maintainers/tetthys)[@tetthys](https://github.com/tetthys)

### Embed Badge

![Health badge](/badges/tetthys-crypto-price/health.svg)

```
[![Health](https://phpackages.com/badges/tetthys-crypto-price/health.svg)](https://phpackages.com/packages/tetthys-crypto-price)
```

###  Alternatives

[iconify/json

Iconify icons collection in JSON format

1.0k61.6k14](/packages/iconify-json)[tarfin-labs/zbar-php

zbar-php is a php package that provides an interface to the zbar bar-code reading library.

26102.3k](/packages/tarfin-labs-zbar-php)[barrelstrength/sprout-reports

Powerful custom reports.

1138.3k3](/packages/barrelstrength-sprout-reports)

PHPackages © 2026

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