package org.knowm.xchange.service;

import java.math.BigDecimal;

import org.knowm.xchange.Exchange;
import org.knowm.xchange.dto.Order;
import org.knowm.xchange.dto.meta.CurrencyPairMetaData;
import org.knowm.xchange.dto.meta.ExchangeMetaData;
import org.knowm.xchange.dto.trade.LimitOrder;
import org.knowm.xchange.dto.trade.MarketOrder;

/**
 * Top of the hierarchy abstract class for an "exchange service"
 */
public abstract class BaseExchangeService {

  /**
   * The base Exchange. Every service has access to the containing exchange class, which hold meta data and the exchange specification
   */
  protected final Exchange exchange;

  /**
   * Constructor
   */
  protected BaseExchangeService(Exchange exchange) {

    this.exchange = exchange;
  }

  public void verifyOrder(LimitOrder limitOrder) {

    ExchangeMetaData exchangeMetaData = exchange.getExchangeMetaData();
    verifyOrder(limitOrder, exchangeMetaData);
    BigDecimal price = limitOrder.getLimitPrice().stripTrailingZeros();

    if (price.scale() > exchangeMetaData.getCurrencyPairs().get(limitOrder.getCurrencyPair()).getPriceScale()) {
      throw new IllegalArgumentException("Unsupported price scale " + price.scale());
    }
  }

  public void verifyOrder(MarketOrder marketOrder) {

    verifyOrder(marketOrder, exchange.getExchangeMetaData());
  }

  final protected void verifyOrder(Order order, ExchangeMetaData exchangeMetaData) {

    CurrencyPairMetaData metaData = exchangeMetaData.getCurrencyPairs().get(order.getCurrencyPair());
    if (metaData == null) {
      throw new IllegalArgumentException("Invalid CurrencyPair");
    }

    BigDecimal originalAmount = order.getOriginalAmount();
    if (originalAmount == null) {
      throw new IllegalArgumentException("Missing originalAmount");
    }

    BigDecimal amount = originalAmount.stripTrailingZeros();
    BigDecimal minimumAmount = metaData.getMinimumAmount();
    if (minimumAmount != null) {
      if (amount.scale() > minimumAmount.scale()) {
        throw new IllegalArgumentException("Unsupported amount scale " + amount.scale());
      } else if (amount.compareTo(minimumAmount) < 0) {
        throw new IllegalArgumentException("Order amount less than minimum");
      }
    }
  }
}

@@ -334,16 +334,52 @@
 Order;%0A%0A
+import si.mazi.rescu.ClientConfig;%0A%0A
 /**%0A * T
@@ -1366,16 +1366,1009 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Get a ClientConfig object which contains exchange-specific timeout values (%3Ci%3EhttpConnTimeout%3C/i%3E and %3Ci%3EhttpReadTimeout%3C/i%3E) if they were present in%0A   * the ExchangeSpecification of this instance. Subclasses are encouraged to use this config object when creating a RestCU proxy.%0A   *%0A   * @return a rescu client config object%0A   */%0A  public ClientConfig getClientConfig() %7B%0A    ClientConfig rescuConfig = new ClientConfig(); // create default rescu config%0A%0A    // set per exchange connection- and read-timeout (if they have been set in the ExchangeSpecification)%0A    int customHttpConnTimeout = exchange.getExchangeSpecification().getHttpConnTimeout();%0A    if (customHttpConnTimeout %3E 0) %7B%0A      rescuConfig.setHttpConnTimeout(customHttpConnTimeout);%0A    %7D%0A    int customHttpReadTimeout = exchange.getExchangeSpecification().getHttpReadTimeout();%0A    if (customHttpReadTimeout %3E 0) %7B%0A      rescuConfig.setHttpReadTimeout(customHttpReadTimeout);%0A    %7D%0A    return rescuConfig;%0A  %7D%0A%0A
   final 

add getClientConfig to BaseExchangeService