package org.knowm.xchange.gdax;

import java.io.IOException;

import org.knowm.xchange.BaseExchange;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.gdax.dto.marketdata.GDAXProduct;
import org.knowm.xchange.gdax.service.GDAXAccountService;
import org.knowm.xchange.gdax.service.GDAXMarketDataService;
import org.knowm.xchange.gdax.service.GDAXMarketDataServiceRaw;
import org.knowm.xchange.gdax.service.GDAXTradeService;
import org.knowm.xchange.utils.nonce.CurrentTime1000NonceFactory;

import si.mazi.rescu.SynchronizedValueFactory;

public class GDAXExchange extends BaseExchange {

  private SynchronizedValueFactory<Long> nonceFactory = new CurrentTime1000NonceFactory();

  @Override
  public void applySpecification(ExchangeSpecification exchangeSpecification) {
    super.applySpecification(exchangeSpecification);
    concludeHostParams(exchangeSpecification);
  }

  @Override
  protected void initServices() {
    concludeHostParams(exchangeSpecification);

    this.marketDataService = new GDAXMarketDataService(this);
    this.accountService = new GDAXAccountService(this);
    this.tradeService = new GDAXTradeService(this);
  }

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

    if (exchangeSpecification.getExchangeSpecificParameters() != null) {
      if (exchangeSpecification.getExchangeSpecificParametersItem("Use_Sandbox").equals(true)) {

        exchangeSpecification.setSslUri("https://api-public.sandbox.gdax.com");
        exchangeSpecification.setHost("api-public.sandbox.gdax.com");

      }
    }
  }

  @Override
  public ExchangeSpecification getDefaultExchangeSpecification() {

    ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass().getCanonicalName());
    exchangeSpecification.setSslUri("https://api.gdax.com");
    exchangeSpecification.setHost("api.gdax.com");
    exchangeSpecification.setPort(80);
    exchangeSpecification.setExchangeName("GDAX");
    exchangeSpecification.setExchangeDescription("GDAX Exchange is a Bitcoin exchange recently launched in January 2015");
    return exchangeSpecification;
  }

  @Override
  public SynchronizedValueFactory<Long> getNonceFactory() {

    return nonceFactory;
  }

  @Override
  public void remoteInit() throws IOException {

    GDAXProduct[] products = ((GDAXMarketDataServiceRaw) marketDataService).getGDAXProducts();
    exchangeMetaData = GDAXAdapters.adaptToExchangeMetaData(exchangeMetaData, products);
  }
}

@@ -715,965 +715,208 @@
 %0A  p
-ublic void applySpecification(ExchangeSpecification exchangeSpecification) %7B%0A    super.applySpecification(exchangeSpecification);%0A    concludeHostParams(exchangeSpecification);%0A  %7D%0A%0A  @Override%0A  protected void initServices() %7B%0A    concludeHostParams(exchangeSpecification);%0A%0A    this.marketDataService = new GDAXMarketDataService(this);%0A    this.accountService = new GDAXAccountService(this);%0A    this.tradeService = new GDAXTradeService(this);%0A  %7D%0A%0A  /**%0A   * Adjust host parameters depending on exchange specific parameters%0A   */%0A  private static void concludeHostParams(ExchangeSpecification exchangeSpecification) %7B%0A%0A    if (exchangeSpecification.getExchangeSpecificParameters() != null) %7B%0A      if (exchangeSpecification.getExchangeSpecificParametersItem(%22Use_Sandbox%22).equals(true)) %7B%0A%0A        exchangeSpecification.setSslUri(%22https://api-public.sandbox.gdax.com%22);%0A        exchangeSpecification.setHost(%22api-public.sandbox.gdax.com%22);%0A%0A      %7D%0A    %7D
+rotected void initServices() %7B%0A    this.marketDataService = new GDAXMarketDataService(this);%0A    this.accountService = new GDAXAccountService(this);%0A    this.tradeService = new GDAXTradeService(this);
 %0A  %7D

Revert "[bitflyer] implemented getOrderBook in MarketDataService, plus tests"