View Javadoc
1   package org.oxerr.peatio.examples.rest;
2   
3   import java.io.IOException;
4   import java.math.BigDecimal;
5   import java.util.Arrays;
6   
7   import org.oxerr.peatio.rest.PeatioException;
8   import org.oxerr.peatio.rest.PeatioExchange;
9   import org.oxerr.peatio.rest.dto.Order;
10  import org.oxerr.peatio.rest.dto.Trade;
11  import org.oxerr.peatio.rest.service.polling.PeatioTradeServiceRaw;
12  import org.slf4j.Logger;
13  import org.slf4j.LoggerFactory;
14  
15  import com.xeiam.xchange.Exchange;
16  import com.xeiam.xchange.ExchangeFactory;
17  import com.xeiam.xchange.ExchangeSpecification;
18  import com.xeiam.xchange.service.polling.trade.PollingTradeService;
19  
20  public class PeatioTradeServiceExample {
21  
22  	private static final Logger log = LoggerFactory
23  			.getLogger(PeatioTradeServiceExample.class);
24  
25  	public static void main(String[] args) throws PeatioException, IOException {
26  		String accessKey = args[0], secretKey = args[1];
27  		boolean demoAsk = args.length > 2 ? Boolean.parseBoolean(args[2]) : false;
28  		boolean demoBid = args.length > 3 ? Boolean.parseBoolean(args[3]) : false;
29  
30  		// Cancel all my orders
31  		boolean clear = args.length > 4 ? Boolean.parseBoolean(args[4]) : false;
32  
33  		Long cancelOrderId = args.length > 5 ? new Long(args[5]) : null;
34  
35  		ExchangeSpecification spec = new ExchangeSpecification(PeatioExchange.class);
36  		spec.setSslUri("https://yunbi.com");
37  		spec.setApiKey(accessKey);
38  		spec.setSecretKey(secretKey);
39  
40  		Exchange peatio = ExchangeFactory.INSTANCE.createExchange(spec);
41  		PollingTradeService tradeService = peatio.getPollingTradeService();
42  		PeatioTradeServiceRaw tradeServiceRaw = (PeatioTradeServiceRaw) tradeService;
43  
44  		final String market = "btccny";
45  
46  		// Get orders
47  		Order[] orders = tradeServiceRaw.getOrders(market, null, null, null, null);
48  		log.info("open order count: {}, orders: {}", orders.length, Arrays.toString(orders));
49  		for (Order order: orders) {
50  			log.info("order: {}", tradeServiceRaw.getOrder(order.getId()));
51  		}
52  
53  		final BigDecimal minVolumePerOrder = new BigDecimal("0.0001");
54  		final BigDecimal minPrice = new BigDecimal("0.01");
55  
56  		if (demoAsk) {
57  			// Place ask order
58  			Order order = tradeServiceRaw.placeOrder(market, "sell",
59  					minVolumePerOrder,
60  					new BigDecimal(Integer.MAX_VALUE), "limit");
61  			log.info("ask order: {}", order);
62  		}
63  		if (demoBid) {
64  			// Place bid order
65  			Order order = tradeServiceRaw.placeOrder(market, "buy",
66  					minVolumePerOrder,
67  					minPrice, "limit");
68  			log.info("bid order: {}", order);
69  		}
70  
71  		if (clear) {
72  			Order[] cancelledOrders = tradeServiceRaw.clearOrders();
73  			log.info("cancelled order: {}", Arrays.toString(cancelledOrders));
74  		}
75  
76  		if (cancelOrderId != null) {
77  			Order deletedOrder = tradeServiceRaw.deleteOrder(cancelOrderId);
78  			log.info("deleted order: {}", deletedOrder);
79  		}
80  
81  		// Get my trades.
82  		Trade[] myTrades = tradeServiceRaw.getMyTrades(market, null, null, null, null, null);
83  		log.info("my trades: {}", Arrays.toString(myTrades));
84  	}
85  
86  }