class FxRateMarketDataFunction implements MarketDataFunction<FxRate, FxRateId> {

  @Override
  public MarketDataBox<FxRate> build(
      FxRateId id,
      MarketDataConfig marketDataConfig,
      ScenarioMarketData marketData,
      ReferenceData refData) {

    FxRateConfig fxRateConfig = marketDataConfig.get(FxRateConfig.class, id.getObservableSource());
    Optional<QuoteId> optional = fxRateConfig.getObservableRateKey(id.getPair());
    return optional.map(key -> buildFxRate(id, key, marketData))
        .orElseThrow(() -> new IllegalArgumentException("No FX rate configuration available for " + id.getPair()));
  }

}