View Javadoc
1   package org.oxerr.chbtc.service.polling;
2   
3   import java.io.IOException;
4   import java.math.BigDecimal;
5   import java.util.List;
6   
7   import org.oxerr.chbtc.dto.Order;
8   import org.oxerr.chbtc.dto.Type;
9   
10  import com.xeiam.xchange.Exchange;
11  
12  public class CHBTCTradeServiceRaw extends CHBTCBaseTradePollingService {
13  
14  	private static final Order[] ORDER_ARRAY = new Order[] {};
15  
16  	protected CHBTCTradeServiceRaw(Exchange exchange) {
17  		super(exchange);
18  	}
19  
20  	/**
21  	 * Place order.
22  	 *
23  	 * @param price the order price.
24  	 * @param amount the order amount.
25  	 * @param tradeType the trade type, buy or sell.
26  	 * @param currency the base symbol in lower case to specifiy market.
27  	 * e.g. btc, ltc.
28  	 * @return the order ID.
29  	 * @throws IOException indicates I/O exception.
30  	 */
31  	public long order(BigDecimal price, BigDecimal amount,
32  			Type tradeType, String currency) throws IOException {
33  		return client.order(price, amount, tradeType, currency);
34  	}
35  
36  	/**
37  	 * Cancel the specified order.
38  	 *
39  	 * @param id the order ID.
40  	 * @param currency the base symbol in lower case to specify the market.
41  	 * e.g. btc, ltc.
42  	 * @throws IOException indicates I/O exception.
43  	 */
44  	public void cancelOrder(long id, String currency) throws IOException {
45  		client.cancelOrder(id, currency);
46  	}
47  
48  	/**
49  	 * Returns order with given order ID in the specified market.
50  	 *
51  	 * @param id the order ID.
52  	 * @param currency the base symbol in lower case to specify market.
53  	 * e.g. btc, ltc.
54  	 * @return the order with given order ID in the specified market.
55  	 * @throws IOException indicates I/O exception.
56  	 */
57  	public Order getOrder(long id, String currency) throws IOException {
58  		return client.getOrder(id, currency);
59  	}
60  
61  	/**
62  	 * Returns bid or ask orders, 10 records maximumly.
63  	 *
64  	 * @param tradeType the trade type, buy or sell.
65  	 * @param currency base symbol in lower case. e.g. btc, ltc.
66  	 * @param pageIndex 1 based.
67  	 * @return bid or ask orders.
68  	 * @throws IOException indicates I/O exception.
69  	 */
70  	public Order[] getOrders(Type tradeType, String currency, int pageIndex)
71  			throws IOException {
72  		List<Order> orderList = client.getOrders(tradeType, currency, pageIndex);
73  		return orderList.toArray(ORDER_ARRAY);
74  	}
75  
76  	/**
77  	 * Returns bid or ask orders.
78  	 *
79  	 * @param tradeType the trade type, buy or sell.
80  	 * @param currency the base symbol in lower case to specify market.
81  	 * e.g. btc, ltc.
82  	 * @param pageIndex 1 based.
83  	 * @param pageSize should not greater than 100.
84  	 * @return bid or ask orders.
85  	 * @throws IOException indicates I/O exception.
86  	 */
87  	public Order[] getOrdersNew(Type tradeType, String currency, int pageIndex,
88  			int pageSize) throws IOException {
89  		List<Order> orderList = client.getOrdersNew(
90  				tradeType, currency, pageIndex, pageSize);
91  		return orderList.toArray(ORDER_ARRAY);
92  	}
93  
94  	/**
95  	 * Returns bid or ask orders.
96  	 *
97  	 * @param currency the base symbol in lower case to specify market.
98  	 * e.g. btc, ltc.
99  	 * @param pageIndex 1 based.
100 	 * @param pageSize should not greater than 100.
101 	 * @return bid or ask orders.
102 	 * @throws IOException indicates I/O exception.
103 	 */
104 	public Order[] getOrdersIgnoreTradeType(String currency, int pageIndex,
105 			int pageSize) throws IOException {
106 		List<Order> orderList = client.getOrdersIgnoreTradeType(
107 				currency, pageIndex, pageSize);
108 		return orderList.toArray(ORDER_ARRAY);
109 	}
110 
111 	/**
112 	 * Returns bid or ask orders.
113 	 *
114 	 * @param currency the base symbol in lower case to specify market.
115 	 * e.g. btc, ltc.
116 	 * @param pageIndex 1 based.
117 	 * @param pageSize should not greater than 100.
118 	 * @return bid or ask orders.
119 	 * @throws IOException indicates I/O exception.
120 	 */
121 	public Order[] getUnfinishedOrdersIgnoreTradeType(String currency,
122 			int pageIndex, int pageSize) throws IOException {
123 		List<Order> orderList = client.getUnfinishedOrdersIgnoreTradeType(
124 				currency,
125 				pageIndex,
126 				pageSize);
127 		return orderList.toArray(ORDER_ARRAY);
128 	}
129 
130 }