Gets an historical rate.

@param HistoricalExchangeRateQuery $exchangeQuery

@return ExchangeRate
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);
    }
1143210
public function getPrice($currency = self::DEFAULT_CURRENCY)
    {
        $priceKey = 'price_'.strtolower($currency);
        $response = $this->request(sprintf('ticker/%s/?convert=%s', static::DECRED_TICKER, $currency));

        if (!isset($response[$priceKey])) {
            throw new \RuntimeException(sprintf('Missing currency rate %s!', $currency));
        }

        return $response[$priceKey];
    }
1008462
public static function getISO4217CurrencyFromCode($code) {
    foreach (Connect2PayCurrencyHelper::$currencies as $currency => $data) {
      if ($data["code"] == $code) {
        return $currency;
      }
    }

    return null;
  }
275567
protected function createRate(CurrencyPairContract $currencyPair, float $rate, \DateTimeInterface $date): ExchangeRate
    {
        return new ExchangeRate($currencyPair, $rate, $date, $this->getName());
    }
821677
public function getFormattedSpecialPriceForCurrency($currency = 'EUR', $formatterLocale = null)
    {
        $price = $this->getSpecialPriceForCurrency($currency);
        if ($price) {
            return $this->getFormattedPrice($price->getPrice(), $currency, $formatterLocale);
        }

        return '';
    }
241111
public function get()
    {
        if ($this->date) {
            $result = $this->historical($this->date, $this->base, $this->targets);
        } else {
            $result = $this->latest($this->base, $this->targets);
        }

        // Ensure the result object is valid.
        if (!$result instanceof ResultContract) {
            throw new UnexpectedValueException('Invalid result type');
        }

        // Perform conversion if requested.
        if ($this->amount !== 1) {
            $converted = $result->rates;

            foreach ($converted as $key => $value) {
                $converted[$key] = round($this->amount * $value, 2);
            }

            // Attach converted values to results.
            $result->setConverted($converted);
        }

        return $result;
    }
510923
private function produceExchangeInstance($exchangeName)
    {
        if (isset($this->declaredExchangeInstances[$exchangeName])) {
            return $this->declaredExchangeInstances[$exchangeName];
        }

        if (isset($this->usedExchangeInstances[$exchangeName])) {
            return $this->usedExchangeInstances[$exchangeName];
        }

        $this->ensureChannel();
        $exchange = new AMQPExchange($this->channel);
        $exchange->setName($exchangeName);
        $this->usedExchangeInstances[$exchangeName] = $exchange;
        return $exchange;
    }
203772
private function doCreateRate(ExchangeRateQuery $exchangeQuery, DateTimeInterface $requestedDate = null): ExchangeRate
    {
        $currencyPair = $exchangeQuery->getCurrencyPair();
        $content = $this->request($this->buildUrl($requestedDate));

        $element = StringUtil::xmlToElement($content);

        $date = new \DateTime((string) $element->xpath('//Tarih_Date/@Date')[0]);
        $elements = $element->xpath('//Currency[@CurrencyCode="'.$currencyPair->getBaseCurrency().'"]/ForexSelling');

        if (!empty($elements) || !$date) {
            return $this->createRate($currencyPair, (float) ($elements[0]), $date);
        }

        throw new UnsupportedCurrencyPairException($currencyPair, $this);
    }
1103300
protected function addUpdateExchangeRate($currencyFrom, $currencyTo, $rate)
    {
        if (!in_array($currencyTo, $this->managedCurrencies)) {
            return false;
        }
        
        $exchangeRate = $this->currencyRateRepository->findOneBy([
            'currencyFrom' => $currencyFrom,
            'currencyTo'   => $currencyTo,
        ]);
        
        if (null === $exchangeRate) {
            $exchangeRate = new CurrencyRate();
            $exchangeRate->setCurrencyFrom($currencyFrom);
            $exchangeRate->setCurrencyTo($currencyTo);
            $exchangeRate->setExchangeRate($rate);
            $this->helper->getEntityManager()->persist($exchangeRate);
        } else {
            $exchangeRate->setExchangeRate($rate);
        }
        
        return true;
    }
719804
protected function getBaseRates(string $currency, string $date)
    {
        $this->currency = $currency;
        $this->date = $date;

        if (isset($this->baseRates[strtoupper($currency)][$date])) {

            return $this->baseRates[strtoupper($currency)][$date];
        }

        return null;
    }
288877
public function findOneWithCurrencyPair(string $firstCurrencyCode, string $secondCurrencyCode): ?ExchangeRateInterface
    {
        $expr = $this->getEntityManager()->getExpressionBuilder();

        return $this->createQueryBuilder('o')
            ->addSelect('sourceCurrency')
            ->addSelect('targetCurrency')
            ->innerJoin('o.sourceCurrency', 'sourceCurrency')
            ->innerJoin('o.targetCurrency', 'targetCurrency')
            ->andWhere($expr->orX(
                'sourceCurrency.code = :firstCurrency AND targetCurrency.code = :secondCurrency',
                'targetCurrency.code = :firstCurrency AND sourceCurrency.code = :secondCurrency'
            ))
            ->setParameter('firstCurrency', $firstCurrencyCode)
            ->setParameter('secondCurrency', $secondCurrencyCode)
            ->getQuery()
            ->getOneOrNullResult()
        ;
    }
464435
@Override
  public UserTrades getTradeHistory(TradeHistoryParams params)
      throws ExchangeException, IOException {

    CurrencyPair pair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
    List<GateioTrade> userTrades = getGateioTradeHistory(pair).getTrades();

    return GateioAdapters.adaptUserTrades(userTrades);
  }
770335
private function retrievePriceByCurrency(array &$prices, $currencyId)
    {
        /** @var ProductPrice $price */
        foreach ($prices as $index => $price) {
            if ($currencyId === $price->getCurrency()->getId()) {
                unset($prices[$index]);

                return $price;
            }
        }

        return null;
    }
60896
public function getCurrency($forceDefault = true)
    {
        $currency = $this->get("thelia.current.currency");

        if (null === $currency && $forceDefault) {
            $currency = Currency::getDefaultCurrency();
        }

        return $currency;
    }
165315
private function retrieveExchangeRateFor(Currency $currency): void
    {
        $conversion = sprintf('%s_%s', $this->baseCurrency->getCode(), $currency->getCode());

        $response = $this->client->request('GET', self::EXCHANGE_RATE_API_URL . '/api/v6/convert', [
            'query' => ['q' => $conversion]
        ]);

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

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

        $this->exchangeRates[$currency->getCode()] = (float) $data['results'][$conversion]['val'];
    }
644398
public function getRate($fromCurrency, $toCurrency)
    {
        if ($fromCurrency === $toCurrency) {
            return 1;
        }

        $currencyString = "{$fromCurrency}-{$toCurrency}";
        if (!isset($this->rates[$currencyString])) {
            throw new NoExchangeRateException(sprintf(
                'Cannot convert %s to %s, no exchange rate found.',
                $fromCurrency,
                $toCurrency
            ));
        }

        return $this->rates[$currencyString];
    }
299938
public function supportQuery(ExchangeRateQuery $exchangeQuery): bool
    {
        $currencyPair = $exchangeQuery->getCurrencyPair();

        return !$exchangeQuery instanceof HistoricalExchangeRateQuery
            && in_array($currencyPair->getBaseCurrency(), $this->getSupportedCodes())
            && in_array($currencyPair->getQuoteCurrency(), $this->getSupportedCodes());
    }