package org.knowm.xchange.bitmex.service;

import java.io.IOException;
import java.util.Arrays;

import org.knowm.xchange.Exchange;
import org.knowm.xchange.bitmex.BitmexAdapters;
import org.knowm.xchange.bitmex.BitmexPrompt;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.marketdata.OrderBook;
import org.knowm.xchange.dto.marketdata.Ticker;
import org.knowm.xchange.dto.marketdata.Trades;
import org.knowm.xchange.exceptions.ExchangeException;
import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException;
import org.knowm.xchange.service.marketdata.MarketDataService;

/**
 * <p>
 * Implementation of the market data service for Bitmex
 * </p>
 * <ul>
 * <li>Provides access to various market data values</li>
 * </ul>
 */
public class BitmexMarketDataService extends BitmexMarketDataServiceRaw implements MarketDataService {

  /**
   * Constructor
   *
   * @param exchange
   */
  public BitmexMarketDataService(Exchange exchange) {

    super(exchange);
  }

  @Override
  public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException {

    throw new NotYetImplementedForExchangeException();
  }

  @Override
  public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {

    BitmexPrompt prompt = null;
    if (args != null && args.length > 0) {
      Object arg0 = args[0];
      if (arg0 instanceof BitmexPrompt) {
        prompt = (BitmexPrompt) arg0;
      }
      else {
        throw new ExchangeException("args[0] must be of type BitmexPrompt!");
      }
    }
    Object[] argsToPass = Arrays.copyOfRange(args, 1, args.length);
    return BitmexAdapters.adaptOrderBook(getBitmexDepth(BitmexAdapters.adaptCurrencyPair(currencyPair), prompt, argsToPass), currencyPair);

  }

  @Override
  public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException {

    Long since = null;
    BitmexPrompt prompt = null;
    if (args != null && args.length > 0) {
      Object arg0 = args[0];
      if (arg0 instanceof BitmexPrompt) {
        prompt = (BitmexPrompt) arg0;
      }
      else {
        throw new ExchangeException("args[0] must be of type BitmexPrompt!");
      }
    }
    Object[] argsToPass = Arrays.copyOfRange(args, 1, args.length);
    // Trades bitmexTrades = getBitmexTrades(BitmexAdapters.adaptCurrencyPair(currencyPair), prompt, argsToPass);
    return getBitmexTrades(BitmexAdapters.adaptCurrencyPair(currencyPair), prompt, argsToPass);

  }
}

@@ -80,19 +80,168 @@
 ava.
-util.Arrays
+math.BigDecimal;%0Aimport java.text.DateFormat;%0Aimport java.text.ParseException;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.Arrays;%0Aimport java.util.List
 ;%0A%0Ai
@@ -368,16 +368,74 @@
 Prompt;%0A
+import org.knowm.xchange.bitmex.dto.account.BitmexTicker;%0A
 import o
@@ -680,83 +680,8 @@
 on;%0A
-import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException;%0A
 impo
@@ -1245,57 +1245,845 @@
     
-throw new NotYetImplementedForExchangeException()
+List%3CBitmexTicker%3E bitmexTickers = getTicker(currencyPair.base.toString() + currencyPair.counter.toString());%0A    BitmexTicker bitmexTicker = bitmexTickers.get(0);%0A%0A    DateFormat format = new SimpleDateFormat(%22yyyy-MM-dd'T'HH:mm:ss.SSS'Z'%22);%0A%0A    Ticker ticker = null;%0A%0A    try %7B%0A      ticker = new Ticker.Builder().currencyPair(currencyPair).open(bitmexTicker.getOpenValue())%0A              .last(bitmexTicker.getLastPrice()).bid(bitmexTicker.getBidPrice()).ask(bitmexTicker.getAskPrice())%0A              .high(bitmexTicker.getHighPrice()).low(bitmexTicker.getLowPrice())%0A              .vwap(new BigDecimal(bitmexTicker.getVwap())).volume(bitmexTicker.getVolume()).quoteVolume(null)%0A              .timestamp(format.parse(bitmexTicker.getTimestamp())).build();%0A    %7D catch (ParseException e) %7B%0A%0A      return null;%0A    %7D%0A%0A    return ticker
 ;%0A  

implement getTicker