1 package org.oxerr.okcoin.websocket.dto; 2 3 import java.math.BigDecimal; 4 import java.text.DecimalFormat; 5 import java.text.ParseException; 6 import java.time.Instant; 7 8 import javax.json.JsonObject; 9 import javax.json.JsonValue; 10 11 public class Ticker extends BaseObject { 12 13 private static final long serialVersionUID = 2015022601L; 14 15 private final BigDecimal buy; 16 private final BigDecimal high; 17 private final BigDecimal last; 18 private final BigDecimal low; 19 private final BigDecimal sell; 20 private final Instant timestamp; 21 private final BigDecimal vol; 22 23 public Ticker(BigDecimal buy, BigDecimal high, BigDecimal last, 24 BigDecimal low, BigDecimal sell, Instant timestamp, BigDecimal vol) { 25 this.buy = buy; 26 this.high = high; 27 this.last = last; 28 this.low = low; 29 this.sell = sell; 30 this.timestamp = timestamp; 31 this.vol = vol; 32 } 33 34 public Ticker(JsonValue jsonValue) { 35 this((JsonObject) jsonValue); 36 } 37 38 public Ticker(JsonObject jsonObject) { 39 this.buy = new BigDecimal(jsonObject.getString("buy")); 40 this.high = new BigDecimal(jsonObject.getString("high")); 41 this.last = new BigDecimal(jsonObject.getString("last")); 42 this.low = new BigDecimal(jsonObject.getString("low")); 43 this.sell = new BigDecimal(jsonObject.getString("sell")); 44 this.timestamp = Instant.ofEpochMilli(Long.parseLong(jsonObject.getString("timestamp"))); 45 DecimalFormat df = new DecimalFormat("#,###."); 46 try { 47 this.vol = BigDecimal.valueOf(df.parse(jsonObject.getString("vol")).doubleValue()); 48 } catch (ParseException e) { 49 throw new IllegalArgumentException(e); 50 } 51 } 52 53 public BigDecimal getBuy() { 54 return buy; 55 } 56 57 public BigDecimal getHigh() { 58 return high; 59 } 60 61 public BigDecimal getLast() { 62 return last; 63 } 64 65 public BigDecimal getLow() { 66 return low; 67 } 68 69 public BigDecimal getSell() { 70 return sell; 71 } 72 73 public Instant getTimestamp() { 74 return timestamp; 75 } 76 77 public BigDecimal getVol() { 78 return vol; 79 } 80 81 }