Get current market rate for currency
480671
def get_rate_for(self, currency: str, to: str, reverse: bool=False) -> Number:
        """"""

        # Return 1 when currencies match
        if currency.upper() == to.upper():
            return self._format_number('1.0')

        # Set base and quote currencies
        base, quote = currency, to
        if reverse:
            base, quote = to, currency

        try:  # Get rate from source
            rate = self._get_rate(base, quote)
        except Exception as e:
            raise ConverterRateError(self.name) from e

        # Convert rate to number
        rate = self._format_number(rate)

        try:  # Validate rate value
            assert isinstance(rate, (float, Decimal))
            assert rate > 0
        except AssertionError as e:
            raise ConverterValidationError(self.name, rate) from e

        # Return market rate
        if reverse:
            return self._format_number('1.0') / rate
        return rate
441359
def _get_price(self, data, market, field):
        
        for m in data:
            if m["symbol"] == market:
                return m[field]
1183971
def get_conversion_rate(from_currency: str, to_currency: str) -> Decimal:
    
    reverse_rate = False
    if to_currency == BASE_CURRENCY:
        # Fetch exchange rate for base currency and use 1 / rate for conversion
        rate_currency = from_currency
        reverse_rate = True
    else:
        rate_currency = to_currency
    rate = get_rate_from_db(rate_currency)

    if reverse_rate:
        conversion_rate = Decimal(1) / rate
    else:
        conversion_rate = rate
    return conversion_rate
884262
def price_value_renderer(value, currency=None, **options):
    """"""
    if not currency:
        currency = getattr(settings, 'CURRENCY', 'USD')
    return format_currency(value, currency, locale=utils.get_current_locale())
969777
def get_price(ctx, currency):
    """"""
    appid = ctx.obj['appid']
    title = ctx.obj['title']

    item_ = Item(appid, title)
    item_.get_price_data(currency)

    click.secho('Lowest price: %s %s' % (item_.price_lowest, item_.price_currency), fg='green')
976133
public function getFor(Currency $currency): float
    {
        if ($currency->equals($this->baseCurrency)) {
            // no need to make an api call for same currencies.
            $this->exchangeRates[$currency->getCode()] = (float) 1;
        } else {
            $this->retrieveExchangeRateFor($currency);
        }

        return $this->exchangeRates[$currency->getCode()];
    }
963046
def get_currency(self):
        
        bika_setup = api.get_bika_setup()
        currency = bika_setup.getCurrency()
        currencies = locales.getLocale('en').numbers.currencies
        return currencies[currency]
1053549
def get_ratetimestamp(self, base, code):
        """"""
        self.get_latestcurrencyrates(base)
        try:
            return datetime.fromtimestamp(self.rates["timestamp"])
        except KeyError:
            return None
799498
def check_update(from_currency, to_currency):
	
	if from_currency not in ccache: # if currency never get converted before
		ccache[from_currency] = {}
	if ccache[from_currency].get(to_currency) is None:
		ccache[from_currency][to_currency] = {'last_update': 0}
	last_update = float(ccache[from_currency][to_currency]['last_update'])
	if time.time() - last_update >= 30 * 60: # if last update is more than 30 min ago
		return True
	return False
858358
def get_rate_source():
    """"""
    backend = money_rates_settings.DEFAULT_BACKEND()
    try:
        return RateSource.objects.get(name=backend.get_source_name())
    except RateSource.DoesNotExist:
        raise CurrencyConversionException(
            "Rate for %s source do not exists. "
            "Please run python manage.py update_rates" % backend.get_source_name())
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];
    }
408293
public function getFormattedBasePriceForCurrency($currency = 'EUR')
    {
        $price = $this->getBasePriceForCurrency($currency);
        if ($price) {
            return $this->getFormattedPrice($price->getPrice(), $currency, $this->locale);
        }

        return '';
    }
1296150
def calculate_rates(base_currency, counter_currency, forward_rate=None, fwd_points=None, spot_reference=None):
    """"""
    if base_currency not in DIVISOR_TABLE:
        divisor = DIVISOR_TABLE.get(counter_currency, DEFAULT_DIVISOR)
        if forward_rate is None and fwd_points is not None and spot_reference is not None:
            forward_rate = spot_reference + fwd_points / divisor
        elif forward_rate is not None and fwd_points is None and spot_reference is not None:
            fwd_points = (forward_rate - spot_reference) * divisor
        elif forward_rate is not None and fwd_points is not None and spot_reference is None:
            spot_reference = forward_rate - fwd_points / divisor

    rates = {}
    if forward_rate is not None:
        rates['forward_rate'] = forward_rate

    if fwd_points is not None:
        rates['fwd_points'] = fwd_points

    if spot_reference is not None:
        rates['spot_reference'] = spot_reference

    return rates
578330
def list_currency_rates(self, from_currency=None):
        
        return self.make_api_request(
            'Account',
            'listCurrencyRates',
            utils.get_kwargs(locals()),
            model=models.CurrencyRate,
        )
1107103
@Override
    public ExchangeRate getExchangeRate(MonetaryAmount amount) {
        return this.rateProvider.getExchangeRate(ConversionQueryBuilder
                .of(conversionQuery).setBaseCurrency(amount.getCurrency())
                .build());
        // return this.rateProvider.getExchangeRate(amount.getCurrency(),
        // getCurrency());
    }
502115
def convert(amount, from_code, to_code, decimals=2, qs=None):
    """"""
    if from_code == to_code:
        return amount

    if qs is None:
        qs = get_active_currencies_qs()

    from_, to = qs.get(code=from_code), qs.get(code=to_code)

    amount = D(amount) * (to.factor / from_.factor)
    return price_rounding(amount, decimals=decimals)
34462
def get_exchange_rate(self, base, target, raise_errors=True):
        """"""
        assert base and target

        base, target = base.lower(), target.lower()

        r = self.session.get(API_SIMPLE_TICKER.format(base, target))
        if r.status_code != requests.codes.ok:
            if not raise_errors:
                return None
            raise CryptonatorException(
                ("An error occurred while getting requested exchange rate "
                 "({} from Cryptonator).").format(r.status_code)
            )

        j = r.json()
        if not j['success'] or j['error']:
            if not raise_errors:
                return None
            raise CryptonatorException(
                ("An error occurred while getting requested exchange rate ({}, {})"
                 "('{}').").format(base, target, j['error'])
            )

        return float(j['ticker']['price'])