View Javadoc
1   package org.oxerr.okcoin.rest.service;
2   
3   import static org.oxerr.okcoin.rest.OKCoinAdapters.adaptOrderBook;
4   import static org.oxerr.okcoin.rest.OKCoinAdapters.adaptSymbol;
5   import static org.oxerr.okcoin.rest.OKCoinAdapters.adaptTicker;
6   
7   import java.io.IOException;
8   
9   import org.knowm.xchange.Exchange;
10  import org.knowm.xchange.currency.CurrencyPair;
11  import org.knowm.xchange.dto.marketdata.OrderBook;
12  import org.knowm.xchange.dto.marketdata.Ticker;
13  import org.knowm.xchange.dto.marketdata.Trades;
14  import org.knowm.xchange.service.marketdata.MarketDataService;
15  import org.oxerr.okcoin.rest.OKCoinAdapters;
16  import org.oxerr.okcoin.rest.dto.Trade;
17  
18  /**
19   * {@link MarketDataService} implementation.
20   */
21  public class OKCoinMarketDataService extends OKCoinMarketDataServiceRaw
22  		implements MarketDataService {
23  
24  	public OKCoinMarketDataService(Exchange exchange) {
25  		super(exchange);
26  	}
27  
28  	/**
29  	 * {@inheritDoc}
30  	 */
31  	@Override
32  	public Ticker getTicker(CurrencyPair currencyPair, Object... args)
33  			throws IOException {
34  		return adaptTicker(getTicker(adaptSymbol(currencyPair)), currencyPair);
35  	}
36  
37  	/**
38  	 * {@inheritDoc}
39  	 */
40  	@Override
41  	public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args)
42  			throws IOException {
43  		return adaptOrderBook(
44  			getDepth(
45  				adaptSymbol(currencyPair),
46  				args.length > 0 ? ((Number) args[0]).intValue() : null,
47  				args.length > 1 ? ((Number) args[1]).intValue() : null),
48  			currencyPair);
49  	}
50  
51  	/**
52  	 * {@inheritDoc}
53  	 */
54  	@Override
55  	public Trades getTrades(CurrencyPair currencyPair, Object... args)
56  			throws IOException {
57  		final String symbol = OKCoinAdapters.adaptSymbol(currencyPair);
58  		final Trade[] trades;
59  		if (args.length == 0) {
60  			trades = getTrades(symbol, (Long) null);
61  		} else {
62  			trades = getTrades(symbol, ((Number) args[0]).longValue());
63  		}
64  		return OKCoinAdapters.adaptTrades(trades, currencyPair);
65  	}
66  
67  }