Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ust.sharedmsgs.ticker;
- import com.activfinancial.contentplatform.contentgatewayapi.FieldListValidator;
- import com.activfinancial.contentplatform.contentgatewayapi.consts.FieldStatus;
- import com.activfinancial.middleware.activbase.MiddlewareException;
- import com.activfinancial.middleware.fieldtypes.Boolean;
- import com.activfinancial.middleware.fieldtypes.*;
- import java.math.BigDecimal;
- import java.sql.Timestamp;
- /**
- * @author danushka
- * 3/21/2020
- */
- public class Quote {
- private long quote_id = 0;
- private Timestamp timestamp = new Timestamp(System.currentTimeMillis());
- private String symbol;
- private BigDecimal price;
- private BigDecimal percentage_change;
- private long trade_time;
- private BigDecimal bid;
- private Integer bid_size;
- private long bid_time;
- private BigDecimal ask;
- private Integer ask_size;
- private long ask_time;
- private BigDecimal limit_heigh;
- private BigDecimal limit_low;
- private boolean is_halted;
- private boolean regular;
- private long cum_vol;
- private BigDecimal cum_val;
- private int event_type;
- private long state;
- private BigDecimal open;
- private String bid_exchange;
- private String ask_exchange;
- private long bid_id = 0;
- private long ask_id = 0;
- public Quote() {
- this.symbol = "";
- this.price = new BigDecimal(0);
- this.percentage_change = new BigDecimal(0);
- this.trade_time = 0;
- this.bid = new BigDecimal(0);
- this.bid_size = 0;
- this.bid_time = 0;
- this.bid_exchange = "";
- this.ask = new BigDecimal(0);
- this.ask_size = 0;
- this.ask_time = 0;
- this.ask_exchange = "";
- this.limit_heigh = new BigDecimal(0);
- this.limit_low = new BigDecimal(0);
- this.is_halted = true;
- this.regular = true;
- this.cum_vol = 0;
- this.cum_val = new BigDecimal(0);
- this.event_type = 0;
- this.state = 0;
- this.open = new BigDecimal(0);
- }
- private Quote(String symbol, BigDecimal price, BigDecimal percentage_change,
- long trade_time, BigDecimal bid, Integer bid_size, long bid_time, String bid_exchange, BigDecimal ask,
- Integer ask_size, long ask_time, String ask_exchange, BigDecimal limit_heigh, BigDecimal limit_low, boolean is_halted,
- boolean regular, long cum_vol, BigDecimal cum_val, int event_type, long state, BigDecimal open) {
- this.symbol = symbol;
- this.price = price;
- this.percentage_change = percentage_change;
- this.trade_time = trade_time;
- this.bid = bid;
- this.bid_size = bid_size;
- this.bid_time = bid_time;
- this.bid_exchange = bid_exchange;
- this.ask = ask;
- this.ask_size = ask_size;
- this.ask_time = ask_time;
- this.ask_exchange = ask_exchange;
- this.limit_heigh = limit_heigh;
- this.limit_low = limit_low;
- this.is_halted = is_halted;
- this.regular = regular;
- this.cum_vol = cum_vol;
- this.cum_val = cum_val;
- this.event_type = event_type;
- this.state = state;
- this.open = open;
- }
- public long getQuote_id() {
- return quote_id;
- }
- public void setQuote_id(long quote_id) {
- this.quote_id = quote_id;
- }
- public Timestamp getTimestamp() {
- return timestamp;
- }
- public void setTimestamp(Timestamp timestamp) {
- this.timestamp = timestamp;
- }
- public String getSymbol() {
- return symbol;
- }
- public void setSymbol(String symbol) {
- this.symbol = symbol;
- }
- public BigDecimal getPrice() {
- return price;
- }
- public void setPrice(BigDecimal price) {
- this.price = price;
- }
- public BigDecimal getPercentage_change() {
- return percentage_change;
- }
- public void setPercentage_change(BigDecimal percentage_change) {
- this.percentage_change = percentage_change;
- }
- public long getTrade_time() {
- return trade_time;
- }
- public void setTrade_time(long trade_time) {
- this.trade_time = trade_time;
- }
- public BigDecimal getBid() {
- return bid;
- }
- public void setBid(BigDecimal bid) {
- this.bid = bid;
- }
- public Integer getBid_size() {
- return bid_size;
- }
- public void setBid_size(Integer bid_size) {
- this.bid_size = bid_size;
- }
- public long getBid_time() {
- return bid_time;
- }
- public void setBid_time(long bid_time) {
- this.bid_time = bid_time;
- }
- public BigDecimal getAsk() {
- return ask;
- }
- public void setAsk(BigDecimal ask) {
- this.ask = ask;
- }
- public Integer getAsk_size() {
- return ask_size;
- }
- public void setAsk_size(Integer ask_size) {
- this.ask_size = ask_size;
- }
- public long getAsk_time() {
- return ask_time;
- }
- public void setAsk_time(long ask_time) {
- this.ask_time = ask_time;
- }
- public BigDecimal getLimit_heigh() {
- return limit_heigh;
- }
- public void setLimit_heigh(BigDecimal limit_heigh) {
- this.limit_heigh = limit_heigh;
- }
- public BigDecimal getLimit_low() {
- return limit_low;
- }
- public void setLimit_low(BigDecimal limit_low) {
- this.limit_low = limit_low;
- }
- public boolean isIs_halted() {
- return is_halted;
- }
- public void setIs_halted(boolean is_halted) {
- this.is_halted = is_halted;
- }
- public boolean isRegular() {
- return regular;
- }
- public void setRegular(boolean regular) {
- this.regular = regular;
- }
- public long getCum_vol() {
- return cum_vol;
- }
- public void setCum_vol(long cum_vol) {
- this.cum_vol = cum_vol;
- }
- public BigDecimal getCum_val() {
- return cum_val;
- }
- public void setCum_val(BigDecimal cum_val) {
- this.cum_val = cum_val;
- }
- public int getEvent_type() {
- return event_type;
- }
- public void setEvent_type(int event_type) {
- this.event_type = event_type;
- }
- public long getState() {
- return state;
- }
- public void setState(long state) {
- this.state = state;
- }
- public BigDecimal getOpen() {
- return open;
- }
- public void setOpen(BigDecimal open) {
- this.open = open;
- }
- public String getBid_exchange() {
- return bid_exchange;
- }
- public void setBid_exchange(String bid_exchange) {
- this.bid_exchange = bid_exchange;
- }
- public String getAsk_exchange() {
- return ask_exchange;
- }
- public void setAsk_exchange(String ask_exchange) {
- this.ask_exchange = ask_exchange;
- }
- public long getBid_id() {
- return bid_id;
- }
- public void setBid_id(long bid_id) {
- this.bid_id = bid_id;
- }
- public long getAsk_id() {
- return ask_id;
- }
- public void setAsk_id(long ask_id) {
- this.ask_id = ask_id;
- }
- public TickerAlgohouseQuoteMsg generateTickerAlgohouseQuoteMsg() {
- return new TickerAlgohouseQuoteMsg(
- quote_id,
- this.getMaximumTimestamp(),
- symbol.replace(".", ""),
- price,
- percentage_change,
- trade_time,
- bid,
- bid_size,
- bid_time,
- ask,
- ask_size,
- ask_time,
- limit_heigh,
- limit_low,
- is_halted,
- false, //todo need to be generated
- cum_vol,
- new BigDecimal(0),
- new BigDecimal(0),
- new BigDecimal(0),
- new BigDecimal(0),
- event_type,
- state
- );
- }
- public TickerMakerQuoteMsg generateTickerMakerQuoteMsg() {
- return new TickerMakerQuoteMsg(
- quote_id,
- this.getMaximumTimestamp(),
- symbol.replace(".", ""),
- price,
- percentage_change,
- trade_time,
- bid,
- bid_size,
- bid_time,
- this.getBidId(),
- ask,
- ask_size,
- ask_time,
- this.getAskId(),
- limit_heigh,
- limit_low,
- is_halted,
- true, //todo need to be generated
- cum_vol,
- cum_val,
- event_type,
- open
- );
- }
- private long getMaximumTimestamp() {
- return Math.max(this.bid_time, Math.max(this.ask_time, this.trade_time));
- }
- public Object convert(String type) {
- if (type.equals("ALGOV2")) {
- return this.generateTickerAlgohouseQuoteMsg();
- } else if (type.equals("MAKERV2")) {
- return this.generateTickerMakerQuoteMsg();
- } else {
- throw new NullPointerException("The subscription type is required");
- }
- }
- public long getAskId() {
- return 0;
- }
- public long getBidId() {
- return 0;
- }
- public Quote updateFields(FieldListValidator fieldListValidator) {
- String symbolId = (String) this.getValue(TickerField.SYMBOL, String.class, fieldListValidator);
- BigDecimal price = (BigDecimal) this.getValue(TickerField.PRICE, BigDecimal.class, fieldListValidator);
- BigDecimal percentage_change = (BigDecimal) this.getValue(TickerField.PERCENTAGE_CHANGE, BigDecimal.class, fieldListValidator);
- long trade_time = (Long) this.getValue(TickerField.TRADE_TIME, Long.class, fieldListValidator);
- BigDecimal bid = (BigDecimal) this.getValue(TickerField.BID, BigDecimal.class, fieldListValidator);
- Integer bid_size = Math.toIntExact((Long) this.getValue(TickerField.BID_SIZE, Long.class, fieldListValidator));
- long bid_time = (Long) this.getValue(TickerField.BID_TIME, Long.class, fieldListValidator);
- String bid_exchange = (String) this.getValue(TickerField.BID_EXCHANGE, String.class, fieldListValidator);
- BigDecimal ask = (BigDecimal) this.getValue(TickerField.ASK, BigDecimal.class, fieldListValidator);
- Integer ask_size = Math.toIntExact((Long) this.getValue(TickerField.ASK_SIZE, Long.class, fieldListValidator));
- long ask_time = (Long) this.getValue(TickerField.ASK_TIME, Long.class, fieldListValidator);
- String ask_exchange = (String) this.getValue(TickerField.ASK_EXCHNAGE, String.class, fieldListValidator);
- BigDecimal limit_heigh = (BigDecimal) this.getValue(TickerField.LIMIT_HIGH, BigDecimal.class, fieldListValidator);
- BigDecimal limit_low = (BigDecimal) this.getValue(TickerField.LIMIT_LOW, BigDecimal.class, fieldListValidator);
- boolean is_halted = false;
- boolean regular = true;
- long cum_vol = (Long) this.getValue(TickerField.CUM_VOL, Long.class, fieldListValidator);
- BigDecimal cum_val = (BigDecimal) this.getValue(TickerField.CUM_VAL, BigDecimal.class, fieldListValidator);
- int event_type = (Integer) this.getValue(TickerField.EVENT_TYPE, Integer.class, fieldListValidator);
- long state = (Long) this.getValue(TickerField.STATE, Long.class, fieldListValidator);
- BigDecimal open = (BigDecimal) this.getValue(TickerField.OPEN, BigDecimal.class, fieldListValidator);
- this.setTimestamp(new Timestamp(System.currentTimeMillis()));
- this.setSymbol(symbolId);
- this.setPrice(price);
- this.setPercentage_change(percentage_change);
- this.setTrade_time(trade_time);
- this.setBid(bid);
- this.setBid_size(bid_size);
- this.setBid_time(bid_time);
- this.setBid_exchange(bid_exchange);
- this.setAsk(ask);
- this.setAsk_size(ask_size);
- this.setAsk_time(ask_time);
- this.setAsk_exchange(ask_exchange);
- this.setLimit_heigh(limit_heigh);
- this.setLimit_low(limit_low);
- this.setIs_halted(is_halted);
- this.setRegular(regular);
- this.setCum_vol(cum_vol);
- this.setCum_val(cum_val);
- this.setEvent_type(event_type);
- this.setState(state);
- this.setOpen(open);
- return this;
- }
- private Object getValue(TickerField fieldId, Class<?> type, FieldListValidator fieldListValidator) {
- FieldListValidator.Field field;
- if ((field = fieldListValidator.getField(fieldId.getCode())) != null) {
- try {
- if (FieldStatus.FIELD_STATUS_DEFINED == field.fieldStatus) {
- switch (field.fieldType.getType()) {
- case 1:
- return (((Time) field.fieldType).getCalendar().getTimeInMillis());
- case 4:
- return ((UInt) field.fieldType).getValue();
- case 5:
- return BigDecimal.valueOf(((Rational) field.fieldType).getDouble());
- case 6:
- return BigDecimal.valueOf(((TRational) (field.fieldType)).getRational().getDouble());
- case 13:
- return ((Boolean) field.fieldType).getValue();
- default:
- return field.fieldType.toString();
- }
- }
- } catch (MiddlewareException e) {
- e.printStackTrace();
- }
- }
- return this.getDefaultTypeValue(type);
- }
- public Object getDefaultTypeValue(Class<?> type) {
- if (type == String.class) return "";
- if (type == Integer.class) return 0;
- if (type == BigDecimal.class) return new BigDecimal(0);
- if (type == Long.class) return 0L;
- else return "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement