function getRateForPair(baseRate, pair) {
    if (pair.length != 6) {
      throw new Error(
        `Invalid pair "${pair}". Must be 6-char string, e.g. "USDEUR"`
      );
    }

    const source = pair.substr(0, 3);
    const target = pair.substr(3, 3);

    if (!baseRate[source]) throw new Error(`Unknown currency code "${source}"`);
    if (!baseRate[target]) throw new Error(`Unknown currency code "${target}"`);

    return {
      id: pair,
      rate: Number(
        source === BASE
          ? baseRate[target]
          : (1 / baseRate[source]) * baseRate[target]
      ).toFixed(6)
    };
  }
Get exchange rate for given pair using given base exchange rate.
Use cross rate if pair's base is not equal to rate base (USD).

@param {object} baseRate - dict { USD: 1, EUR: 0.834499, ... }
@param {string} pair - "USDEUR", "EURUSD", "EURJPY", etc
@return {object} dict { id: "USDEUR", rate: "0.834499" }