package org.knowm.xchange.bibox.service;

import java.io.IOException;
import java.util.Collection;

import org.knowm.xchange.Exchange;
import org.knowm.xchange.bibox.dto.BiboxAdapters;
import org.knowm.xchange.dto.Order;
import org.knowm.xchange.dto.trade.LimitOrder;
import org.knowm.xchange.dto.trade.MarketOrder;
import org.knowm.xchange.dto.trade.OpenOrders;
import org.knowm.xchange.dto.trade.StopOrder;
import org.knowm.xchange.dto.trade.UserTrades;
import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException;
import org.knowm.xchange.service.trade.TradeService;
import org.knowm.xchange.service.trade.params.CancelOrderParams;
import org.knowm.xchange.service.trade.params.TradeHistoryParams;
import org.knowm.xchange.service.trade.params.orders.OpenOrdersParams;

/**
 * @author odrotleff
 */
public class BiboxTradeService extends BiboxTradeServiceRaw implements TradeService {

  public BiboxTradeService(Exchange exchange) {
    super(exchange);
  }

  @Override
  public OpenOrders getOpenOrders() throws IOException {
    return BiboxAdapters.adaptOpenOrders(getBiboxOpenOrders());
  }

  @Override
  public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
    throw new NotYetImplementedForExchangeException("This operation is not yet implemented for this exchange");
  }

  @Override
  public String placeMarketOrder(MarketOrder marketOrder) throws IOException {
    throw new NotYetImplementedForExchangeException("This operation is not yet implemented for this exchange");
  }

  @Override
  public String placeLimitOrder(LimitOrder limitOrder) throws IOException {
    return placeBiboxLimitOrder(limitOrder).toString();
  }

  @Override
  public boolean cancelOrder(String orderId) throws IOException {
    cancelBiboxOrder(orderId);
    return true;
  }

  @Override
  public boolean cancelOrder(CancelOrderParams orderParams) throws IOException {
    throw new NotYetImplementedForExchangeException("This operation is not yet implemented for this exchange");
  }

  @Override
  public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    throw new NotYetImplementedForExchangeException("This operation is not yet implemented for this exchange");
  }

  @Override
  public TradeHistoryParams createTradeHistoryParams() {
    throw new NotYetImplementedForExchangeException("This operation is not yet implemented for this exchange");
  }

  @Override
  public OpenOrdersParams createOpenOrdersParams() {
    throw new NotYetImplementedForExchangeException("This operation is not yet implemented for this exchange");
  }

  @Override
  public void verifyOrder(MarketOrder marketOrder) {
    throw new NotYetImplementedForExchangeException("This operation is not yet implemented for this exchange");
  }

  @Override
  public Collection<Order> getOrder(String... orderIds) throws IOException {
    throw new NotYetImplementedForExchangeException("This operation is not yet implemented for this exchange");
  }

  @Override
  public String placeStopOrder(StopOrder arg0) throws IOException {
    throw new NotYetImplementedForExchangeException("This operation is not yet implemented for this exchange");
  }

  @Override
  public void verifyOrder(LimitOrder limitOrder) {
    throw new NotYetImplementedForExchangeException("This operation is not yet implemented for this exchange");
  }
}

@@ -449,16 +449,71 @@
 Trades;%0A
+import org.knowm.xchange.exceptions.ExchangeException;%0A
 import o
@@ -632,16 +632,85 @@
 ervice;%0A
+import org.knowm.xchange.service.trade.params.CancelOrderByIdParams;%0A
 import o
@@ -2030,115 +2030,231 @@
     
-throw new NotYetImplementedForExchangeException(%22This operation is not yet implemented for this exchange%22);
+if (orderParams instanceof CancelOrderByIdParams) %7B%0A      return cancelOrder(((CancelOrderByIdParams) orderParams).getOrderId());%0A    %7D else %7B%0A      throw new ExchangeException(%22Need order ID for cancelling orders.%22);%0A    %7D
 %0A  %7D

Implement cancelOrder() with CancelOrderParams