PHPackages                             stichoza/nbg-currency - 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. stichoza/nbg-currency

ActiveLibrary[API Development](/categories/api)

stichoza/nbg-currency
=====================

National Bank of Georgia (NBG) currency service API wrapper

v3.1.1(8mo ago)3025.6k↑57.1%81MITPHPPHP ^8.1CI failing

Since Jan 3Pushed 8mo ago2 watchersCompare

[ Source](https://github.com/Stichoza/nbg-currency)[ Packagist](https://packagist.org/packages/stichoza/nbg-currency)[ Docs](https://github.com/Stichoza/nbg-currency)[ Fund](https://btc.com/bc1qc25j4x7yahghm8nnn6lypnw59nptylsw32nkfl)[ Fund](https://www.paypal.me/stichoza)[ RSS](/packages/stichoza-nbg-currency/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (3)Versions (21)Used By (1)

NBG Currency
============

[](#nbg-currency)

[![Latest Stable Version](https://camo.githubusercontent.com/f157333040f7519fb8ebbd2d743df0acb2b63e0f4dbebd78c2f7e109a29a3465/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f53746963686f7a612f6e62672d63757272656e63792e737667)](https://packagist.org/packages/stichoza/nbg-currency) [![Total Downloads](https://camo.githubusercontent.com/2ee212ca2aa035287c6f76cdb6bc800f5677be6ee250fc3bc16c1f98e6d8bc68/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f53746963686f7a612f6e62672d63757272656e63792e737667)](https://packagist.org/packages/stichoza/nbg-currency)

National Bank of Georgia (NBG) currency service API wrapper in PHP

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

[](#installation)

Install this package via [Composer](https://getcomposer.org/).

```
composer require stichoza/nbg-currency

```

Note

PHP 8.1 or later is required. Use following versions of this package for older PHP versions:

Package versionPHP VersionDocumentation`v3.1`PHP &gt;= 8.1[v3 Docs](#nbg-currency)`v2.0`PHP &gt;= 7.1.8[v2 Docs](https://github.com/Stichoza/nbg-currency/tree/2.0#nbg-currency)`v1.2`PHP &gt;= 5.5.9[v1.2 Docs](https://github.com/Stichoza/nbg-currency/tree/1.2#nbg-currency) (Not working)Quick Examples
--------------

[](#quick-examples)

```
NbgCurrency::rate('usd'); // 2.7177
NbgCurrency::rate('usd', '2022-12-02'); // 2.7112

NbgCurrency::get('usd')->rate; // 2.7177
NbgCurrency::get('usd', '2022-12-02')->rate; // 2.7112
NbgCurrency::get('usd', '2022-12-02', 'en')->name; // US Dollar

NbgCurrency::date(Carbon::yesterday())->get('usd')->diff; // 0.0012
NbgCurrency::date('2022-12-02', 'en')->get('usd')->increased(); // true
```

Continue reading for more details about additional functionality.

Basic Usage
-----------

[](#basic-usage)

The class is namespaced as `Stichoza\NbgCurrency\NbgCurrency`:

```
use Stichoza\NbgCurrency\NbgCurrency;
```

This package has three main static methods from which you can access currency rates.

### Get Currency Rate

[](#get-currency-rate)

The `NbgCurrency::rate()` method returns a currency rate in `float`.

```
NbgCurrency::rate(string $code, DateTimeInterface|string|null $date = null): float
```

ParameterDefaultDescription`$code`Currency code, not case-sensitive`$date``null`Date of currency rate: [Carbon](https://carbon.nesbot.com), [DateTime](https://www.php.net/manual/en/class.datetime.php), string or null.Caution

The rate is always for a **single unit**. The original NBG JSON API returns rate for different amounts per currency. For example Japanese Yen (JPY) rate will be 1.9865 and quantity will be set to 100 (100 JPY is 1.9865 GEL). It is quite confusing during calculations so **this package always returns price per single unit**. So in this case JPY will be 0.019865 (1 JPY is 0.019865 GEL).

**Examples:**

```
NbgCurrency::rate('usd'); // Returns current rate of USD. Example: 2.7177
NbgCurrency::rate('usd', '2022-12-02'); // USD rate on 2022-12-02
NbgCurrency::rate('eur', 'yesterday'); // EUR rate from yesterday. Strings are parsed via Carbon::parse()
NbgCurrency::rate('eur', Carbon::yesterday()); // EUR rate from yesterday
NbgCurrency::rate('gbp', Carbon::today()->subDays(5)); // GBP rate 5 days ago
NbgCurrency::rate('gbp', new DateTime()); // GBP rate today

if (NbgCurrency::rate('usd') > 3) {
    echo 'Oh no!';
}
```

When passing dates as [`Carbon`](https://carbon.nesbot.com) or `DateTime` objects, it's recommended to have its timezone set to `Asia/Tbilisi` to avoid unexpected behavior. For convenience, timezone string is available as `NbgCurrency::TIMEZONE` class constant.

### Get Currency Object

[](#get-currency-object)

The `NbgCurrency::get()` method returns a `Currency` object containing data of a currency for specified date.

This method accepts same parameters as `::rate()` method and one additional parameter for language (Used for currency name).

```
NbgCurrency::get(string $code, DateTimeInterface|string|null $date = null, string $language = 'ka'): Currency
```

ParameterDefaultDescription`$code`Currency code, not case-sensitive`$date``null`Date of currency rate`$language``ka`Language for currency name (Currently only `en` or `ka`)**Examples:**

```
$usd = NbgCurrency::get('usd'); // Currency object (Stichoza\NbgCurrency\Data\Currency)

$usd->code; // USD
$usd->rate; // 2.7112
$usd->name; // აშშ დოლარი
$usd->diff; // -0.0065
$usd->date; // Carbon object of date: 2022-12-01 17:45:12
$usd->validFrom; // Carbon object since when the rate is valid: 2022-12-02 00:00:00
$usd->change; // Currency rate change. -1 if decreased, 0 if unchanged and 1 if increased.

// Using methods available on Carbon objects
$usd->date->format('j F Y'); // 1 December 2022
$usd->date->diffForHumans(); // 3 days ago
$usd->validFrom->isPast(); // true

// Additional methods
$usd->increased(); // Returns true if rate has increased, false otherwise.
$usd->decreased(); // Returns true if rate has decreased, false otherwise.
$usd->unchanged(); // Returns true if rate hasn't changed, false otherwise.

// The changeString() method returns first parameter if rate was increased, second string if there was
// no change and third string if the rate went up. Useful for CSS classes, font icons, etc.
$class = $usd->changeString('text-red', 'text-gray', 'text-green');
$icon  = $usd->changeString('fa-arrow-down', 'fa-circle', 'fa-arrow-down');
```

Important

All properties of `Currency` class are declared as `readonly`. Updating them will result in Fatal Error.

Advanced Usage
--------------

[](#advanced-usage)

### Get All Currencies

[](#get-all-currencies)

The `NbgCurrency::date()` method will return a `Currencies` object. This is a collection-like object that contains a list of all `Currency` objects available for specified date.

```
NbgCurrency::date(DateTimeInterface|string|null $date = null, string $language = 'ka'): Currencies
```

ParameterDefaultDescription`$date``null`Date of currency rates`$language``ka`Language for names of currencies (Currently only `en` or `ka`)**Examples:**

```
$currencies = NbgCurrency::date('3 days ago');
$currencies = NbgCurrency::date(Carbon::now()->startOfMonth(), 'en');
```

`Currencies` class has date attribute and several methods that you can use.

```
$currencies->date; // Carbon object of date

$currencies->get('usd'); // Returns Currency object for USD
$currencies->has('eur'); // True if EUR currency is contained in $currencies collection
$currencies->count(); // Count of Currency objects in collection

$currencies->get('usd')->rate; // Currency rate of USD
$currencies->get('eur')->date->diffForHumans(); // 10 days ago
```

Note that `->get()` method of `Currencies` object has only one parameter `string $code`, while the static method with the same name (`NbgCurrency::get()`) has two additional parameters described in basic usage examples above.

The `Currencies` object also implements `Countable` and `IteratorAggregate` interfaces, so you can use the object in `foreach` loops and `count()` function.

**Examples:**

```
$currencies = NbgCurrency::date('2022-12-02', 'en'); // Currencies object (Stichoza\NbgCurrency\Data\Currencies)

echo 'Total ' . count($currencies) . ' currencies for ' . $currencies->date->toFormattedDateString();
// Total 43 currencies for Dec 2, 2022

foreach ($currencies as $code => $currency) {
    echo $currency->code . ' costs ' . $currency->rate;
}
// AED costs 7.3662
// AMD costs 6.8453
// ...
```

Error Handling
--------------

[](#error-handling)

There are 5 exceptions in `Stichoza\NbgCurrency\Exceptions` namespace that could be thrown from methods:

- `CurrencyNotFoundException` - If currency is not available.
- `DateNotFoundException` - If specified date is not available.
- `LanguageNotFoundException` - If specified language is not available.
- `InvalidDateException` - If the specified date is in invalid format or cannot be parsed.
- `RequestFailedException` - If there was an error during API request.

All exceptions above extend `Exception` class, so you can handle all exceptions by catching `Exception` or `Throwable`.

```
try {
    $usdRate = NbgCurrency::date('10 days ago', 'en')->get('usd')->rate;
} catch (Exception) {
    // Whoops...
}
```

Additional Info
---------------

[](#additional-info)

### Number of HTTP Requests

[](#number-of-http-requests)

When you access any currency, all currencies for that day in selected language will be fetched (API returns all currencies in a single request) and stored in NbgCurrency class attribute. When you request any other currency, no additional HTTP requests will be made for same date and language.

```
// Next 3 method calls will result in 1 HTTP request in total.
NbgCurrency::rate('usd');
NbgCurrency::rate('eur');
NbgCurrency::rate('gbp');

// Next 3 method calls will result in 3 HTTP requests in total.
NbgGurrency::rate('usd', '2022-10-10');
NbgGurrency::rate('eur', '2022-11-11', 'en');
NbgGurrency::rate('gbp', '2022-11-11');

// Next 3 method calls will result in 2 HTTP request in total.
NbgGurrency::rate('usd', '2022-11-11');
NbgGurrency::rate('eur', '2022-11-11');
NbgGurrency::rate('gbp', '2022-11-11', 'en');
```

### Memory Usage &amp; Caching

[](#memory-usage--caching)

By default, all retrieved currencies are stored in a static property of `NbgCurrency` class. If you're planning to get currencies for many different dates, it might use excessive memory. In this case it's recommended to turn off the caching feature.

```
NbgCurrency::disableCaching(); // Disable caching, also removes data stored in the property.
NbgCurrency::enableCaching(); // Enables caching in class property.
```

On the other hand, disabling caching may increase number of HTTP requests being sent. Example:

```
$codes = ['USD', 'EUR', 'GBP', 'UAH', 'JPY'];

foreach ($codes as $code) {
    echo NbgCurrency::rate($code);
}
```

The above code would make a single HTTP request to the API when caching is enabled. But if you disable caching, it will send 5 separate HTTP requests. To load multiple currencies of same date using a single HTTP request with caching disabled, you can use `::date()` method to get `Currencies` object and then access all contained objects after.

```
$codes = ['USD', 'EUR', 'GBP', 'UAH', 'JPY'];

$currencies = NbgCurrency::date();

foreach ($codes as $code) {
    echo $currencies->get($code)->rate;
}
```

In this case there will be a single HTTP request made even with caching disabled.

### Keywords

[](#keywords)

> ლარის კურსი, ეროვნული ბანკის გაცვლითი კურსი, ვალუტა, ლარის ვალუტის კურსი, laris kursi, laris valuta, lari currency, national bank of georgia, nbg

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance62

Regular maintenance activity

Popularity38

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 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

Every ~189 days

Recently: every ~267 days

Total

20

Last Release

242d ago

Major Versions

v0.1.0 → v1.0.02016-01-03

v1.2.3 → v2.0.02020-03-29

v2.0.3 → v3.0.02022-12-04

PHP version history (4 changes)v0.0.1PHP &gt;=5.5.9

v2.0.0PHP &gt;=7.1.8

2.0.x-devPHP &gt;=7.1.8|^8.0

v3.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1139050?v=4)[Levan Velijanashvili](/maintainers/stichoza)[@Stichoza](https://github.com/Stichoza)

---

Top Contributors

[![Stichoza](https://avatars.githubusercontent.com/u/1139050?v=4)](https://github.com/Stichoza "Stichoza (141 commits)")

---

Tags

currencycurrency-convertercurrency-exchange-ratesgelgeorgiageorgianlarinbgcurrencyBankRategeorgianbgvalutakursi

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stichoza-nbg-currency/health.svg)

```
[![Health](https://phpackages.com/badges/stichoza-nbg-currency/health.svg)](https://phpackages.com/packages/stichoza-nbg-currency)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.6M986](/packages/statamic-cms)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k420.9k26](/packages/team-reflex-discord-php)[florianv/swap-bundle

Drop-in Symfony bundle for currency conversion: configurable services, multi-provider exchange rates with fallback and caching.

64431.5k1](/packages/florianv-swap-bundle)[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)[codebar-ag/laravel-docuware

DocuWare integration with Laravel

1123.7k](/packages/codebar-ag-laravel-docuware)

PHPackages © 2026

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