2020-06-07 22:38:10 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Entity\PriceInformations\Currency;
|
|
|
|
use Brick\Math\BigDecimal;
|
|
|
|
use Swap\Swap;
|
|
|
|
|
|
|
|
class ExchangeRateUpdater
|
|
|
|
{
|
2022-09-18 22:59:31 +02:00
|
|
|
private string $base_currency;
|
|
|
|
private Swap $swap;
|
2020-06-07 22:38:10 +02:00
|
|
|
|
|
|
|
public function __construct(string $base_currency, Swap $swap)
|
|
|
|
{
|
|
|
|
$this->base_currency = $base_currency;
|
|
|
|
$this->swap = $swap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the exchange rate of the given currency using the globally configured providers.
|
|
|
|
*/
|
|
|
|
public function update(Currency $currency): Currency
|
|
|
|
{
|
|
|
|
$rate = $this->swap->latest($currency->getIsoCode().'/'.$this->base_currency);
|
|
|
|
$currency->setExchangeRate(BigDecimal::of($rate->getValue()));
|
2020-08-21 21:36:22 +02:00
|
|
|
|
2020-06-07 22:38:10 +02:00
|
|
|
return $currency;
|
|
|
|
}
|
2020-08-21 21:36:22 +02:00
|
|
|
}
|