{"id":21072912,"url":"https://github.com/h4kuna/exchange","last_synced_at":"2026-02-26T04:56:02.495Z","repository":{"id":1625202,"uuid":"2323615","full_name":"h4kuna/exchange","owner":"h4kuna","description":"ČNB, ECB, RB exchange rates, fiat exchange, built-in cache, expandable for other banks, PSR-7, 17, 18","archived":false,"fork":false,"pushed_at":"2025-02-03T07:03:12.000Z","size":366,"stargazers_count":23,"open_issues_count":0,"forks_count":14,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T05:06:42.644Z","etag":null,"topics":["api","bank","cnb","ecb","exchange"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/h4kuna.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["h4kuna"],"custom":["https://revolut.me/milan2m/czk1000/exchange"]}},"created_at":"2011-09-04T15:07:44.000Z","updated_at":"2025-02-04T11:20:52.000Z","dependencies_parsed_at":"2023-10-11T09:03:51.397Z","dependency_job_id":"55c5f882-06f2-4497-af99-5539e22f7b9e","html_url":"https://github.com/h4kuna/exchange","commit_stats":{"total_commits":194,"total_committers":6,"mean_commits":"32.333333333333336","dds":0.4020618556701031,"last_synced_commit":"946114c52d9ee76a068e789e8504924748c2c7d0"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h4kuna%2Fexchange","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h4kuna%2Fexchange/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h4kuna%2Fexchange/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h4kuna%2Fexchange/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h4kuna","download_url":"https://codeload.github.com/h4kuna/exchange/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441053,"owners_count":20939239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","bank","cnb","ecb","exchange"],"created_at":"2024-11-19T18:59:22.641Z","updated_at":"2026-02-26T04:56:02.446Z","avatar_url":"https://github.com/h4kuna.png","language":"PHP","funding_links":["https://github.com/sponsors/h4kuna","https://revolut.me/milan2m/czk1000/exchange"],"categories":[],"sub_categories":[],"readme":"Exchange\n-------\n[![Downloads this Month](https://img.shields.io/packagist/dm/h4kuna/exchange.svg)](https://packagist.org/packages/h4kuna/exchange)\n[![Latest Stable Version](https://poser.pugx.org/h4kuna/exchange/v/stable?format=flat)](https://packagist.org/packages/h4kuna/exchange)\n[![Coverage Status](https://coveralls.io/repos/github/h4kuna/exchange/badge.svg?branch=master)](https://coveralls.io/github/h4kuna/exchange?branch=master)\n[![Total Downloads](https://poser.pugx.org/h4kuna/exchange/downloads?format=flat)](https://packagist.org/packages/h4kuna/exchange)\n[![License](https://poser.pugx.org/h4kuna/exchange/license?format=flat)](https://packagist.org/packages/h4kuna/exchange)\n\nExchange is PHP script works with currencies. You can convert price.\n\nHere is [changelog](changelog.md).\n\n## Extension for framework\n\n- [Nette extension](//github.com/h4kuna/exchange-nette)\n\n## Installation via composer\n\n```sh\n$ composer require h4kuna/exchange\n```\nOptional packages\n```sh\n$ composer require malkusch/lock guzzlehttp/guzzle guzzlehttp/psr7 h4kuna/dir nette/caching\n```\n\nSupport PSR-6 for cache.\n\n## How to use\n\nInit object [Exchange](src/Exchange.php) by [ExchangeFactory](src/ExchangeFactory.php). Default Driver for read is [Cnb](src/Driver/Cnb/Day.php), [here are others](src/Driver).\n\nFor example define own exchange rates:\n\n- 25 CZK = 1 EUR\n- 20 CZK = 1 USD\n\n```php\nuse h4kuna\\Exchange\\Currency\\Property;\nuse h4kuna\\Exchange\\Driver\\Cnb\\Day;\nuse h4kuna\\Exchange\\Exchange;\nuse h4kuna\\Exchange\\ExchangeFactory;\nuse h4kuna\\Exchange\\RatingList\\CacheEntity;\nuse h4kuna\\Exchange\\RatingList\\RatingList;\n\n{ # by factory\n\t$exchangeFactory = new ExchangeFactory(\n\t\tfrom: 'eur',\n\t\tto: 'usd',\n\t\tallowedCurrencies: [\n\t\t\t'CZK',\n\t\t\t'USD',\n\t\t\t'eur', // lower case will be changed to upper case\n\t\t],\n\t);\n\n\t$exchange = $exchangeFactory-\u003ecreate();\n}\n\n{ # custom RatingList\n\t$ratingList = new RatingList(new DateTimeImmutable(), new DateTimeImmutable(), null, [\n\t\t'EUR' =\u003e new Property(1, 25.0, 'EUR'),\n\t\t'USD' =\u003e new Property(1, 20.0, 'USD'),\n\t\t'CZK' =\u003e new Property(1, 1.0, 'CZK'),\n\t]);\n\t$exchange = new Exchange('EUR', $ratingList, 'USD');\n}\n\necho $exchange-\u003echange(100) . PHP_EOL; // EUR -\u003e USD = 125.0\n\n// use only upper case\necho $exchange-\u003echange(100, 'CZK') . PHP_EOL; // CZK -\u003e USD = 5.0\necho $exchange-\u003echange(100, null, 'CZK') . PHP_EOL; // EUR -\u003e CZK = 2500.0\necho $exchange-\u003echange(100, 'USD', 'CZK') . PHP_EOL; // USD -\u003e CZK = 2000.0\n```\n\n### Change driver and date\n\nDownload history exchange rates. Make new instance of Exchange with history rate.\n\n```php\nuse h4kuna\\Exchange\\RatingList;\nuse h4kuna\\Exchange;\n\n$exchangePast = $exchangeFactory-\u003ecreate(cacheEntity: new CacheEntity(new Datetime('2000-12-30'), new Day));\necho $exchangePast-\u003echange(100) . PHP_EOL;\n```\n\n### Access and iterator\n\n```php\nuse h4kuna\\Exchange\\Currency\\Property;\n/* @var $property Property */\n$property = $exchange['EUR'];\nvar_dump($property);\necho PHP_EOL;\n\nforeach ($exchange as $code =\u003e $property) {\n\t/* @var $property Property */\n\tvar_dump($code, $property);\n}\n```\n\n## Caching\n\nThe cache invalid automatic at some time, defined by property `SourceData::$refresh`. From this property is counted time to live. Little better is invalid cache by cron. Because one request on server does not lock other requests. Let's run cron max. 29 minutes before invalidate cache.\n```php\nuse h4kuna\\Exchange\\RatingList\\RatingListCache;\nuse h4kuna\\Exchange\\RatingList\\CacheEntity;\nuse h4kuna\\Exchange\\Driver\\Cnb\\Day;\n\n/** @var RatingListCache $ratingListCache */\n$ratingListCache-\u003erebuild(new CacheEntity(null, new Day));\n```\n\nIn example, is used `h4kuna\\Exchange\\Driver\\Cnb\\Day::$refresh` is defined at 14:30 + 30 minute the cache is valid. Run cron 14:32 every day.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh4kuna%2Fexchange","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh4kuna%2Fexchange","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh4kuna%2Fexchange/lists"}