georgii-web / cbr-api-exchange
Cbr.ru exchange rate API package. Gets currency rate from Russian Central Bank API, http://www.cbr.ru.
Requires
- php: ^7.4|^8.0
- ext-libxml: *
- ext-simplexml: *
- nesbot/carbon: ^2.16
Requires (Dev)
- jetbrains/phpstorm-attributes: dev-master
- pestphp/pest: 1.x-dev
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-master
- vimeo/psalm: ^4.3
This package is auto-updated.
Last update: 2024-10-16 20:36:33 UTC
README
Cbr.ru exchange API.
Gets currency rate from Russian Central Bank API, http://www.cbr.ru.
All currencies list: http://www.cbr.ru/scripts/XML_val.asp?d=0
Get USD rate example url: http://www.cbr.ru/scripts/XML_dynamic.asp?date_req1=01/01/2021&date_req2=12/01/2021&VAL_NM_RQ=R01235
Features
Centrak Bank announce exchange rate for tomorrow everyday (in a second part of the day).
On holidays there are no announcements, so it uses previous date of the exchange rate.
For example, on 2020-12-31 at 08:00 we don't get exchange rate for 2021-01-01, but at 21:00 we'll get it. And if we check exchange rate on 2021-01-04 we get it for 2021-01-01.
Install
$ composer require georgii-web/cbr-api-exchange
How to
Add class
use CbrApiExchange\CbrApiExchange;
Use examples
CbrApiExchange::get(); // Get default currency 'R01235'(USD) on default date 'Today()'
CbrApiExchange::get('R01239'); // Get currency 'R01239'(EUR) on default date 'Today()'
CbrApiExchange::get('R01239', '2021-01-01'); // Get currency 'R01239'(EUR) on date '2021-01-01'
Returns
[
"code" => "R01235", // The actual currency code
"date" => "2021-01-01", // The actual date of the exchange rate
"rate" => 73.8757, // Exchange rate of this currency to the Ruble
]
Development
Testing
$ ./vendor/bin/pest
Psalm check
$ ./vendor/bin/psalm