View Javadoc
1   package org.oxerr.peatio.websocket.dto;
2   
3   import java.math.BigDecimal;
4   import java.time.Instant;
5   
6   import javax.json.JsonObject;
7   
8   import org.oxerr.peatio.rest.dto.BaseObject;
9   
10  public class OrderBook extends BaseObject {
11  
12  	private final String action;
13  	private final Order order;
14  	private final String locale;
15  
16  	public OrderBook(String action, Order order, String locale) {
17  		this.action = action;
18  		this.order = order;
19  		this.locale = locale;
20  	}
21  
22  	public OrderBook(JsonObject jsonObject) {
23  		this.action = jsonObject.getString("action");
24  		this.order = new Order(jsonObject.getJsonObject("order"));
25  		this.locale = jsonObject.getString("locale");
26  	}
27  
28  	public String getAction() {
29  		return action;
30  	}
31  
32  	public Order getOrder() {
33  		return order;
34  	}
35  
36  	public String getLocale() {
37  		return locale;
38  	}
39  
40  	public static class Order extends BaseObject {
41  		private final long id;
42  		private final Instant timestamp;
43  		private final String type;
44  		private final BigDecimal volume;
45  		private final BigDecimal price;
46  		private final String market;
47  		private final String ordType;
48  
49  		public Order(JsonObject jsonObject) {
50  			this.id = jsonObject.getJsonNumber("id").longValue();
51  			this.timestamp = Instant.ofEpochSecond(jsonObject.getJsonNumber("timestamp").longValue());
52  			this.type = jsonObject.getString("type");
53  			this.volume = new BigDecimal(jsonObject.getString("volume"));
54  			this.price = new BigDecimal(jsonObject.getString("price"));
55  			this.market = jsonObject.getString("market");
56  			this.ordType = jsonObject.getString("ord_type");
57  		}
58  
59  		public long getId() {
60  			return id;
61  		}
62  
63  		public Instant getTimestamp() {
64  			return timestamp;
65  		}
66  
67  		public String getType() {
68  			return type;
69  		}
70  
71  		public BigDecimal getVolume() {
72  			return volume;
73  		}
74  
75  		public BigDecimal getPrice() {
76  			return price;
77  		}
78  
79  		public String getMarket() {
80  			return market;
81  		}
82  
83  		public String getOrdType() {
84  			return ordType;
85  		}
86  
87  	}
88  
89  }