View Javadoc
1   package org.oxerr.okcoin.examples.rest;
2   
3   import java.io.IOException;
4   
5   import org.knowm.xchange.Exchange;
6   import org.knowm.xchange.ExchangeFactory;
7   import org.knowm.xchange.ExchangeSpecification;
8   import org.knowm.xchange.currency.CurrencyPair;
9   import org.knowm.xchange.dto.trade.UserTrades;
10  import org.knowm.xchange.service.trade.TradeService;
11  import org.oxerr.okcoin.rest.OKCoinExchange;
12  import org.oxerr.okcoin.rest.service.OKCoinTradeService.OKCoinTradeHistoryParams;
13  import org.slf4j.Logger;
14  import org.slf4j.LoggerFactory;
15  
16  /**
17   * Demonstration of getting order history.
18   */
19  public class TradeHistoryDemo {
20  
21  	private final Logger log = LoggerFactory.getLogger(TradeHistoryDemo.class);
22  
23  	private final TradeService tradeService;
24  
25  	public TradeHistoryDemo(Exchange exchange) {
26  		tradeService = exchange.getTradeService();
27  	}
28  
29  	public void demoGetTradeHistory() throws IOException {
30  		OKCoinTradeHistoryParams params = (OKCoinTradeHistoryParams) tradeService.createTradeHistoryParams();
31  		params.setCurrencyPair(CurrencyPair.BTC_CNY);
32  		params.setPageNumber(1);
33  		params.setPageLength(10);
34  
35  		UserTrades userTrades = tradeService.getTradeHistory(params);
36  		userTrades.getUserTrades().forEach(
37  			userTrade -> log.info("ID: {}, OrderID: {}, {} {} {}@{}",
38  				userTrade.getId(),
39  				userTrade.getOrderId(),
40  				userTrade.getTimestamp(),
41  				userTrade.getType(),
42  				userTrade.getTradableAmount(),
43  				userTrade.getPrice()));
44  	}
45  
46  	public static void main(String[] args) throws IOException {
47  		String apiKey = args[0], secretKey = args[1];
48  
49  		ExchangeSpecification spec = new ExchangeSpecification(OKCoinExchange.class);
50  		spec.setApiKey(apiKey);
51  		spec.setSecretKey(secretKey);
52  
53  		Exchange domesticExchange = ExchangeFactory.INSTANCE.createExchange(spec);
54  		TradeHistoryDemo tradeHistoryDemo = new TradeHistoryDemo(domesticExchange);
55  
56  		tradeHistoryDemo.demoGetTradeHistory();
57  	}
58  
59  }