Creates the rate.

@param ExchangeRateQuery $exchangeQuery
@param DateTimeInterface $requestedDate

@return ExchangeRate

@throws UnsupportedCurrencyPairException
546345
private function doCreateRate(ExchangeRateQuery $exchangeQuery, DateTimeInterface $requestedDate): ExchangeRate
    {
        $currencyPair = $exchangeQuery->getCurrencyPair();
        $content = $this->request($this->buildUrl($requestedDate));

        $lines = explode("\n", $content);

        if (!$date = \DateTime::createFromFormat(self::DATE_FORMAT, $this->parseDate($lines[0]))) {
            throw new UnsupportedCurrencyPairException($currencyPair, $this);
        }

        $date->setTime(0, 0, 0);
        foreach (array_slice($lines, 2) as $line) {
            if (!preg_match(self::CURRENCY_LINE_PATTERN, $line)) {
                continue;
            }
            list(, , $count, $code, $rate) = explode('|', $line);

            if ($code === $currencyPair->getBaseCurrency()) {
                $rate = (float) str_replace(',', '.', $rate);

                return $this->createRate($currencyPair, (float) ($rate / (int) $count), $date);
            }
        }

        throw new UnsupportedCurrencyPairException($currencyPair, $this);
    }
1341239
private function buildUrl(DateTimeInterface $requestedDate): string
    {
        return self::URL.'?'.http_build_query([self::DATE_QUERY_PARAMETER_NAME => $requestedDate->format(self::DATE_FORMAT)]);
    }
458535
public function getTaxedPrice($untaxedPrice, &$taxCollection = null, $askedLocale = null)
    {
        if (null === $this->taxRulesCollection) {
            throw new TaxEngineException('Tax rules collection is empty in Calculator::getTaxedPrice', TaxEngineException::UNDEFINED_TAX_RULES_COLLECTION);
        }

        if (null === $this->product) {
            throw new TaxEngineException('Product is empty in Calculator::getTaxedPrice', TaxEngineException::UNDEFINED_PRODUCT);
        }

        if (false === filter_var($untaxedPrice, FILTER_VALIDATE_FLOAT)) {
            throw new TaxEngineException('BAD AMOUNT FORMAT', TaxEngineException::BAD_AMOUNT_FORMAT);
        }

        $taxedPrice = $untaxedPrice;
        $currentPosition = 1;
        $currentTax = 0;

        if (null !== $taxCollection) {
            $taxCollection = new OrderProductTaxCollection();
        }
        foreach ($this->taxRulesCollection as $taxRule) {
            $position = (int) $taxRule->getTaxRuleCountryPosition();

            $taxType = $taxRule->getTypeInstance();

            if ($currentPosition !== $position) {
                $taxedPrice += $currentTax;
                $currentTax = 0;
                $currentPosition = $position;
            }

            $taxAmount = $taxType->calculate($this->product, $taxedPrice);
            $currentTax += $taxAmount;

            if (null !== $taxCollection) {
                $taxI18n = I18n::forceI18nRetrieving($askedLocale, 'Tax', $taxRule->getId());
                $orderProductTax = new OrderProductTax();
                $orderProductTax->setTitle($taxI18n->getTitle());
                $orderProductTax->setDescription($taxI18n->getDescription());
                $orderProductTax->setAmount($taxAmount);
                $taxCollection->addTax($orderProductTax);
            }
        }

        $taxedPrice += $currentTax;

        return $taxedPrice;
    }
977423
private function retrieveExchangeRateFor(Currency $currency): void
    {
        $response = $this->client->request('GET', self::EXCHANGE_RATE_API_URL . '/latest', [
            'query' => [
                'access_key' => $this->apiKey,
                'base'       => $this->baseCurrency->getCode(),
            ],
        ]);

        $data = json_decode($response->getBody(), true);

        if ($data['success'] !== true) {
            throw FixerIoException::couldNotRetrieveRates($data['error']);
        }

        if (! array_key_exists($currency->getCode(), $data['rates'])) {
            throw FixerIoException::currencyNotFound($currency->getCode());
        }

        $this->exchangeRates[$currency->getCode()] = $data['rates'][$currency->getCode()];
    }
387578
public static LimitOrder adaptOrder(
      BigDecimal originalAmount,
      BigDecimal price,
      String tradedCurrency,
      String transactionCurrency,
      String orderTypeString,
      String id,
      Date timestamp) {

    // place a limit order
    OrderType orderType = adaptSide(orderTypeString);
    CurrencyPair currencyPair = adaptCurrencyPair(tradedCurrency, transactionCurrency);

    LimitOrder limitOrder =
        new LimitOrder(orderType, originalAmount, currencyPair, id, timestamp, price);

    return limitOrder;
  }
127176
public function createNewProductPriceForCurrency(
        ProductInterface $product,
        $priceValue,
        $minimumQuantity = 0.0,
        $currencyId = null
    ) {
        // Fetch currency.
        if (!$currencyId) {
            $currency = $this->currencyRepository->findByCode($this->defaultCurrency);
        } else {
            $currency = $this->currencyRepository->find($currencyId);
        }

        if (!$currency) {
            throw new ProductDependencyNotFoundException($this->currencyRepository->getClassName(), $currencyId);
        }

        $productPrice = new ProductPrice();
        $productPrice->setMinimumQuantity($minimumQuantity);
        $productPrice->setPrice($priceValue);
        $productPrice->setProduct($product);
        $productPrice->setCurrency($currency);
        $product->addPrice($productPrice);

        return $productPrice;
    }
97231
public function load($sourceCurrencyCode, $destinationCurrencyCode)
    {
        $rate = null;

        $exchangeRates = $this->loadAll();

        if (isset($exchangeRates[$sourceCurrencyCode][$destinationCurrencyCode])) {
            $rate = $exchangeRates[$sourceCurrencyCode][$destinationCurrencyCode];
        } // Conversion rates are two-way. If a reverse rate is unavailable, set it.
        elseif (isset($exchangeRates[$destinationCurrencyCode][$sourceCurrencyCode])) {
            $rate = bcdiv(1,
              $exchangeRates[$destinationCurrencyCode][$sourceCurrencyCode],
              6);
        }

        if ($rate) {
            return new ExchangeRate($sourceCurrencyCode,
              $destinationCurrencyCode, $rate);
        }

        return null;
    }
5207
public function getRateModel($base = null, $date = null) : Rates
    {
        $base = strtoupper($base);
        if (empty($base)) {
            $base = 'USD';
        }
        if (empty($date)) {
            $date = date('Y-m-d');
        }
        $this->fromCache = false;
        $api = $this->api;

        if ($this->cacheEnabled) {
            $cachekey = "cc-$api-$base-$date";

            $rates = Cache::get($cachekey);
            if (is_object($rates) and isset($rates->rates)) {
                $this->fromCache = true;
                if ($this->logEnabled) {
                    Log::debug("Got currency rates from cache: $cachekey");
                }
            }
            else {
                $rates = $this->provider->rates($base, $date);
                if (!empty($rates->rates)) {
                    if(Cache::add($cachekey, $rates, $this->cacheMinutes) and $this->logEnabled) {
                        Log::debug('Added new currency rates to cache: '.$cachekey.' for '.$this->cacheMinutes.' min.');
                    }
                }
            }
        }
        else {
            $rates = $this->provider->rates($base, $date);
        }

        if (empty($rates->rates)) {
            Log::warning("$rates->error -> $rates->url");
        }

        return $rates;
    }
769491
public function build()
    {
        if ($this->date) {
            return new HistoricalExchangeRateQuery($this->currencyPair, $this->date, $this->options);
        }

        return new ExchangeRateQuery($this->currencyPair, $this->options);
    }
1166263
protected function exchangeRates($baseCurrency, $defaultCurrency, array $currencyRates)
    {
        $precision = 5;
        $defaultCurrencyRate = round(1 / $currencyRates[$defaultCurrency], $precision);

        $exchangedRates = array();
        $exchangedRates[$baseCurrency] = $defaultCurrencyRate;

        unset($currencyRates[$baseCurrency], $currencyRates[$defaultCurrency]);

        foreach ($currencyRates as $currencyName => $rate) {
            $exchangedRates[$currencyName] = round($rate * $defaultCurrencyRate, $precision);
        }

        return $exchangedRates;
    }
13584
private function getHistoricalExchangeRate(HistoricalExchangeRateQuery $exchangeQuery): ExchangeRate
    {
        $date = $exchangeQuery->getDate();
        $currencyPair = $exchangeQuery->getCurrencyPair();
        $rate = (float) $this->historicalRates[$date->format('Y-m-d')][(string) $currencyPair];

        return $this->createRate($currencyPair, $rate, $date);
    }
669140
private function createExchangeRate(CurrencyInterface $sourceCurrency, CurrencyInterface $targetCurrency, $ratio = 1.00)
    {
        /** @var ExchangeRateInterface $exchangeRate */
        $exchangeRate = $this->exchangeRateFactory->createNew();
        $exchangeRate->setSourceCurrency($sourceCurrency);
        $exchangeRate->setTargetCurrency($targetCurrency);
        $exchangeRate->setRatio((float) $ratio);

        return $exchangeRate;
    }
1065341
public ExchangeRateBuilder toBuilder() {
        return new ExchangeRateBuilder(getContext()).setBase(getBaseCurrency()).setTerm(getCurrency())
                .setFactor(getFactor()).setRateChain(getExchangeRateChain());
    }
792022
@Override
    public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
        for (ExchangeRateProvider prov : this.providers) {
            try {
                if (prov.isAvailable(conversionQuery)) {
                    ExchangeRate rate = prov.getExchangeRate(conversionQuery);
                    if (Objects.nonNull(rate)) {
                        return rate;
                    }
                }
            } catch (Exception e) {
                throw new CurrencyConversionException(conversionQuery.getBaseCurrency(), conversionQuery.getCurrency(), null,
                    "Rate Provider did not return data though at check before data was flagged as available," +
                        " provider=" + prov.getContext().getProviderName() + ", query=" + conversionQuery, e);
            }
        }
        throw new CurrencyConversionException(conversionQuery.getBaseCurrency(), conversionQuery.getCurrency(), null,
                "All delegate prov iders failed to deliver rate, providers=" + this.providers +
                        ", query=" + conversionQuery);
    }
580972
public function create(CurrencyCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $currency = new CurrencyModel();

        $isDefault = CurrencyQuery::create()->count() === 0;

        $currency
            ->setDispatcher($dispatcher)
            ->setLocale($event->getLocale())
            ->setName($event->getCurrencyName())
            ->setSymbol($event->getSymbol())
            ->setFormat($event->getFormat())
            ->setRate($event->getRate())
            ->setCode(strtoupper($event->getCode()))
            ->setByDefault($isDefault)
            ->save()
        ;

        $event->setCurrency($currency);
    }
930979
public static ExchangeRate retrieve(String currency) throws StripeException {
    return retrieve(currency, (Map<String, Object>) null, (RequestOptions) null);
  }
222045
public function getExchangeRate()
    {
        try {
            $currentCurrency = $this->storeManager->getStore()->getCurrentCurrency()->getCode();
            $baseCurrency = $this->storeManager->getStore()->getBaseCurrency()->getCode();
            return (float)$this->currencyFactory->create()->load($baseCurrency)->getAnyRate($currentCurrency);
        } catch (\Exception $e) {
            throw $e;
        }
    }