package com.xeiam.xchange.btctrade.service.polling;

import com.xeiam.xchange.ExchangeSpecification;
import com.xeiam.xchange.NotAvailableFromExchangeException;
import com.xeiam.xchange.btctrade.BTCTradeAdapters;
import com.xeiam.xchange.btctrade.dto.BTCTradeResult;
import com.xeiam.xchange.btctrade.dto.trade.BTCTradePlaceOrderResult;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.Order.OrderType;
import com.xeiam.xchange.dto.marketdata.Trades;
import com.xeiam.xchange.dto.trade.LimitOrder;
import com.xeiam.xchange.dto.trade.MarketOrder;
import com.xeiam.xchange.dto.trade.OpenOrders;
import com.xeiam.xchange.service.polling.PollingTradeService;

public class BTCTradeTradeService extends BTCTradeTradeServiceRaw implements PollingTradeService {

  /**
   * @param exchangeSpecification
   */
  public BTCTradeTradeService(ExchangeSpecification exchangeSpecification) {

    super(exchangeSpecification);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public OpenOrders getOpenOrders() {

    return BTCTradeAdapters.adaptOpenOrders(getBTCTradeOrders(0, "open"), CurrencyPair.BTC_CNY);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String placeMarketOrder(MarketOrder marketOrder) {

    throw new NotAvailableFromExchangeException();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String placeLimitOrder(LimitOrder limitOrder) {

    final BTCTradePlaceOrderResult result;
    if (limitOrder.getType() == OrderType.BID) {
      result = buy(limitOrder.getTradableAmount(), limitOrder.getLimitPrice());
    }
    else {
      result = sell(limitOrder.getTradableAmount(), limitOrder.getLimitPrice());
    }
    return BTCTradeAdapters.adaptPlaceOrderResult(result);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public boolean cancelOrder(String orderId) {

    BTCTradeResult result = cancelBTCTradeOrder(orderId);
    return BTCTradeAdapters.adaptResult(result);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public Trades getTradeHistory(Object... arguments) {

    long since = arguments.length > 0 ? toLong(arguments[0]) : 0L;
    return BTCTradeAdapters.adaptTrades(getBTCTradeOrders(since, "all"), CurrencyPair.BTC_CNY);
  }

}

@@ -46,16 +46,74 @@
 lling;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A
 import c
@@ -310,32 +310,91 @@
 BTCTradeResult;%0A
+import com.xeiam.xchange.btctrade.dto.trade.BTCTradeOrder;%0A
 import com.xeiam
@@ -894,16 +894,99 @@
 vice %7B%0A%0A
+  private final Logger log = LoggerFactory.getLogger(BTCTradeTradeService.class);%0A%0A
   /**%0A  
@@ -2294,39 +2294,32 @@
 ) : 0L;%0A    
-return 
 BTCTrade
 Adapters.ada
@@ -2310,29 +2310,25 @@
 rade
-Adapters.adaptTrades(
+Order%5B%5D orders = 
 getB
@@ -2354,16 +2354,225 @@
 , %22all%22)
+;%0A    log.debug(%22Enriching %7B%7D orders.%22, orders.length);%0A    for (int i = 0; i %3C orders.length; i++) %7B%0A      orders%5Bi%5D = getBTCTradeOrder(orders%5Bi%5D.getId());%0A    %7D%0A    return BTCTradeAdapters.adaptTrades(orders
 , Curren

Fix BTCTradeTradeService.getTradeHistory(Object...), as no detail trades in the returned order list.