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

import java.io.IOException;

import si.mazi.rescu.SynchronizedValueFactory;

import com.xeiam.xchange.ExchangeSpecification;
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.dto.trade.UserTrades;
import com.xeiam.xchange.kraken.KrakenAdapters;
import com.xeiam.xchange.service.polling.PollingTradeService;

public class KrakenTradeService extends KrakenTradeServiceRaw implements PollingTradeService {

  public KrakenTradeService(ExchangeSpecification exchangeSpecification, SynchronizedValueFactory<Long> nonceFactory) {

    super(exchangeSpecification, nonceFactory);
  }

  @Override
  public OpenOrders getOpenOrders() throws IOException {

    return KrakenAdapters.adaptOpenOrders(super.getKrakenOpenOrders());
  }

  @Override
  public String placeMarketOrder(MarketOrder marketOrder) throws IOException {

    return KrakenAdapters.adaptOrderId(super.placeKrakenMarketOrder(marketOrder));
  }

  @Override
  public String placeLimitOrder(LimitOrder limitOrder) throws IOException {

    return KrakenAdapters.adaptOrderId(super.placeKrakenLimitOrder(limitOrder));
  }

  @Override
  public boolean cancelOrder(String orderId) throws IOException {

    return super.cancelKrakenOrder(orderId).getCount() > 0;
  }

  @Override
  public UserTrades getTradeHistory(Object... args) throws IOException {

    return KrakenAdapters.adaptTradesHistory(super.getKrakenTradeHistory());
  }

  @Override
  public Object createTradeHistoryParams() {
    return null;
  }

}

@@ -72,16 +72,106 @@
 eption;%0A
+import java.util.Date;%0A%0Aimport com.xeiam.xchange.service.polling.opt.TradeHistoryTimeSpan;
 %0Aimport 
@@ -559,16 +559,51 @@
 rvice;%0A%0A
+import javax.annotation.Nullable;%0A%0A
 public c
@@ -1588,32 +1588,394 @@
  IOException %7B%0A%0A
+    Long start = null;%0A    Long end = null;%0A%0A    if (args.length == 1) %7B%0A      Object arg0 = args%5B0%5D;%0A      if (arg0 instanceof TradeHistoryParam) %7B%0A        TradeHistoryParam param = (TradeHistoryParam) arg0;%0A        if (param.from != null)%0A          start = param.from.getTime();%0A        if (param.to != null)%0A          end = param.to.getTime();%0A      %7D%0A    %7D%0A%0A
     return Krake
@@ -2003,22 +2003,16 @@
 History(
-super.
 getKrake
@@ -2025,16 +2025,45 @@
 History(
+null, false, start, end, null
 ));%0A  %7D%0A
@@ -2136,16 +2136,563 @@
 rn n
-ull;%0A  %7D%0A
+ew TradeHistoryParam();%0A  %7D%0A%0A  public static class TradeHistoryParam implements TradeHistoryTimeSpan%7B%0A    @Nullable%0A    private Date from;%0A    @Nullable%0A    private Date to;%0A%0A    public TradeHistoryParam() %7B%0A    %7D%0A%0A    public TradeHistoryParam(Date from) %7B%0A      this.from = from;%0A    %7D%0A%0A    public TradeHistoryParam(Date from, Date to) %7B%0A      this.from = from;%0A      this.to = to;%0A    %7D%0A%0A    @Override%0A    public void setToTime(Date to) %7B%0A      this.to = to;%0A    %7D%0A%0A    @Override%0A    public void setFromTime(Date from) %7B%0A      this.from = from;%0A    %7D%0A  %7D
 %0A%7D%0A

Implement parametrized TradeService.getTradeHistory