class BitmexExchange extends BaseExchange implements Exchange {

  protected RateLimitUpdateListener rateLimitUpdateListener;

  private final SynchronizedValueFactory<Long> nonceFactory =
      new SynchronizedValueFactory<Long>() {

        private final SynchronizedValueFactory<Long> secondsNonce =
            new CurrentTimeIncrementalNonceFactory(TimeUnit.SECONDS);

        @Override
        public Long createValue() {
          return secondsNonce.createValue() + 30;
        }
      };

  /** Adjust host parameters depending on exchange specific parameters */
  private static void concludeHostParams(ExchangeSpecification exchangeSpecification) {

    if (exchangeSpecification.getExchangeSpecificParameters() != null) {
      if (exchangeSpecification
          .getExchangeSpecificParametersItem(Exchange.USE_SANDBOX)
          .equals(true)) {
        exchangeSpecification.setSslUri("https://testnet.bitmex.com");
        exchangeSpecification.setHost("testnet.bitmex.com");
      }
    }
  }

  @Override
  public void applySpecification(ExchangeSpecification exchangeSpecification) {

    super.applySpecification(exchangeSpecification);

    concludeHostParams(exchangeSpecification);
  }

  @Override
  protected void initServices() {

    concludeHostParams(exchangeSpecification);

    this.marketDataService = new BitmexMarketDataService(this);
    this.accountService = new BitmexAccountService(this);
    this.tradeService = new BitmexTradeService(this);
  }

  @Override
  public ExchangeSpecification getDefaultExchangeSpecification() {

    ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass());
    exchangeSpecification.setSslUri("https://www.bitmex.com");
    exchangeSpecification.setHost("bitmex.com");
    exchangeSpecification.setPort(80);
    exchangeSpecification.setExchangeName("Bitmex");
    exchangeSpecification.setExchangeDescription("Bitmex is a bitcoin exchange");
    exchangeSpecification.setExchangeSpecificParametersItem(Exchange.USE_SANDBOX, false);
    return exchangeSpecification;
  }

  @Override
  public SynchronizedValueFactory<Long> getNonceFactory() {
    return nonceFactory;
  }

  @Override
  public void remoteInit() throws IOException {
    updateExchangeMetaData();
  }

  public RateLimitUpdateListener getRateLimitUpdateListener() {
    return rateLimitUpdateListener;
  }

  public void setRateLimitUpdateListener(RateLimitUpdateListener rateLimitUpdateListener) {
    this.rateLimitUpdateListener = rateLimitUpdateListener;
  }

  public void updateExchangeMetaData() {<FILL_FUNCTION_BODY>}

  private void collectCurrenciesAndPairs(
      BitmexTicker ticker, List<CurrencyPair> activeCurrencyPairs, Set<Currency> activeCurrencies) {

    String bitmexSymbol = ticker.getSymbol();
    String baseSymbol =
        ("XBK".equals(ticker.getRootSymbol()) || "XBJ".equals(ticker.getRootSymbol()))
            ? "XBT"
            : ticker.getRootSymbol();
    String counterSymbol;

    if (bitmexSymbol.contains(baseSymbol)) {
      counterSymbol = bitmexSymbol.substring(baseSymbol.length());
    } else {
      logger.warn("Not clear how to create currency pair for symbol: {}", bitmexSymbol);
      return;
    }

    activeCurrencyPairs.add(new CurrencyPair(baseSymbol, counterSymbol));
    activeCurrencies.add(new Currency(baseSymbol));
    activeCurrencies.add(new Currency(counterSymbol));
  }

  private Integer getPriceScale(List<BitmexTicker> tickers, CurrencyPair cp) {

    return tickers.stream()
        .filter(ticker -> ticker.getSymbol().equals(BitmexAdapters.adaptCurrencyPairToSymbol(cp)))
        .findFirst()
        .map(BitmexTicker::getLastPrice)
        .filter(Objects::nonNull)
        .map(BigDecimal::scale)
        .orElse(null);
  }

  public CurrencyPair determineActiveContract(
      String baseSymbol, String counterSymbol, BitmexPrompt contractTimeframe) {

    if ("BTC".equals(baseSymbol)) {
      baseSymbol = "XBT";
    }
    if ("BTC".equals(counterSymbol)) {
      counterSymbol = "XBT";
    }

    final String symbols = baseSymbol + "/" + counterSymbol;

    BitmexTickerList tickerList =
        ((BitmexMarketDataServiceRaw) marketDataService)
            .getTicker(baseSymbol + ":" + contractTimeframe);

    String bitmexSymbol =
        tickerList.stream()
            .map(BitmexTicker::getSymbol)
            .findFirst()
            .orElseThrow(
                () ->
                    new ExchangeException(
                        String.format(
                            "Instrument for %s %s is not active or does not exist",
                            symbols, contractTimeframe)));

    String contractTypeSymbol = bitmexSymbol.substring(3);
    return new CurrencyPair(baseSymbol, contractTypeSymbol);
  }
}


    List<BitmexTicker> tickers =
        ((BitmexMarketDataServiceRaw) marketDataService).getActiveTickers();
    List<CurrencyPair> activeCurrencyPairs = new ArrayList<>();
    Set<Currency> activeCurrencies = new HashSet<>();

    tickers.forEach(
        ticker -> collectCurrenciesAndPairs(ticker, activeCurrencyPairs, activeCurrencies));

    Map<Instrument, InstrumentMetaData> pairsMap = exchangeMetaData.getInstruments();
    Map<Currency, CurrencyMetaData> currenciesMap = exchangeMetaData.getCurrencies();

    // Remove pairs that are no-longer in use
    pairsMap.keySet().retainAll(activeCurrencyPairs);

    // Remove currencies that are no-longer in use
    currenciesMap.keySet().retainAll(activeCurrencies);

    // Add missing pairs and currencies
    activeCurrencyPairs.forEach(
        cp -> {
          if (!pairsMap.containsKey(cp)) {
            pairsMap.put(
                cp,
                new InstrumentMetaData.Builder()
                    .minimumAmount(BigDecimal.ONE)
                    .priceScale(getPriceScale(tickers, cp))
                    .build());
          }
          if (!currenciesMap.containsKey(cp.base)) {
            currenciesMap.put(cp.base, null);
          }
          if (!currenciesMap.containsKey(cp.counter)) {
            currenciesMap.put(cp.counter, null);
          }
        });
  
<methods>public non-sealed void <init>() ,public void applySpecification(org.knowm.xchange.ExchangeSpecification) ,public org.knowm.xchange.service.account.AccountService getAccountService() ,public List<org.knowm.xchange.instrument.Instrument> getExchangeInstruments() ,public org.knowm.xchange.dto.meta.ExchangeMetaData getExchangeMetaData() ,public org.knowm.xchange.ExchangeSpecification getExchangeSpecification() ,public org.knowm.xchange.service.marketdata.MarketDataService getMarketDataService() ,public java.lang.String getMetaDataFileName(org.knowm.xchange.ExchangeSpecification) ,public SynchronizedValueFactory<java.lang.Long> getNonceFactory() ,public org.knowm.xchange.service.trade.TradeService getTradeService() ,public void remoteInit() throws java.io.IOException, org.knowm.xchange.exceptions.ExchangeException,public java.lang.String toString() <variables>protected org.knowm.xchange.service.account.AccountService accountService,protected org.knowm.xchange.dto.meta.ExchangeMetaData exchangeMetaData,protected org.knowm.xchange.ExchangeSpecification exchangeSpecification,protected final Logger logger,protected org.knowm.xchange.service.marketdata.MarketDataService marketDataService,private final SynchronizedValueFactory<java.lang.Long> nonceFactory,protected org.knowm.xchange.service.trade.TradeService tradeService