Rev 763 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 760 | blopes | 1 | package br.com.sl.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.math.BigDecimal; |
||
| 5 | import java.time.LocalDateTime; |
||
| 6 | import java.time.ZoneId; |
||
| 7 | import java.util.Date; |
||
| 8 | |||
| 9 | import javax.persistence.Column; |
||
| 10 | import javax.persistence.Entity; |
||
| 11 | import javax.persistence.GeneratedValue; |
||
| 12 | import javax.persistence.GenerationType; |
||
| 13 | import javax.persistence.Id; |
||
| 14 | import javax.persistence.JoinColumn; |
||
| 15 | import javax.persistence.ManyToOne; |
||
| 16 | import javax.persistence.SequenceGenerator; |
||
| 17 | import javax.persistence.Table; |
||
| 18 | import javax.persistence.Transient; |
||
| 19 | import javax.validation.constraints.NotNull; |
||
| 20 | |||
| 21 | import org.hibernate.annotations.ForeignKey; |
||
| 22 | |||
| 23 | import br.com.ec.core.interfaces.Alterar; |
||
| 24 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 764 | blopes | 25 | import br.com.ec.core.util.DataUtils; |
| 760 | blopes | 26 | import br.com.ec.core.util.VerificadorUtil; |
| 27 | import br.com.kronus.core.Timeframe; |
||
| 28 | import br.com.sl.domain.dto.robo.CandleState; |
||
| 29 | import br.com.sl.domain.model.tipos.TipoPeriodoCandle; |
||
| 762 | blopes | 30 | import br.com.sl.domain.util.BigDecimalUtils; |
| 760 | blopes | 31 | |
| 32 | @Entity |
||
| 33 | @Table(name="slp_candle", schema="sc_slp") |
||
| 34 | public class Candle implements Serializable { |
||
| 35 | |||
| 36 | private static final long serialVersionUID = 1L; |
||
| 37 | |||
| 38 | private Long sequencial; |
||
| 764 | blopes | 39 | private Integer contadorCandle; |
| 760 | blopes | 40 | private Ativo ativo; |
| 41 | private Date dataHora; |
||
| 42 | private BigDecimal abertura; |
||
| 43 | private BigDecimal maxima; |
||
| 44 | private BigDecimal minima; |
||
| 45 | private BigDecimal fechamento; |
||
| 46 | private BigDecimal volume; |
||
| 47 | private String periodo; |
||
| 48 | |||
| 761 | blopes | 49 | private String nomeAtivo; |
| 760 | blopes | 50 | private LocalDateTime dataHoraTime; |
| 51 | private Timeframe periodoTimeFramde; |
||
| 763 | blopes | 52 | private Boolean candleAnalisado = false; |
| 760 | blopes | 53 | |
| 54 | public Candle() {} |
||
| 55 | |||
| 56 | public Candle(Ativo ativo, LocalDateTime fimCandle, CandleState situacaoCandle, String periodoCandle) { |
||
| 57 | this.ativo = ativo; |
||
| 58 | this.dataHora = Date.from(situacaoCandle.getLastTickTime().atZone(ZoneId.systemDefault()).toInstant()); |
||
| 59 | this.abertura = situacaoCandle.getAbertura(); |
||
| 60 | this.maxima = situacaoCandle.getMaxima(); |
||
| 61 | this.minima = situacaoCandle.getMinima(); |
||
| 62 | this.fechamento = situacaoCandle.getFechamento(); |
||
| 63 | this.periodo = periodoCandle; |
||
| 64 | } |
||
| 761 | blopes | 65 | |
| 764 | blopes | 66 | public Candle(Integer contador, String ativoDescricao, LocalDateTime time, BigDecimal abertura, BigDecimal topo, BigDecimal fundo, |
| 761 | blopes | 67 | BigDecimal fechamento, String periodoCandle) { |
| 764 | blopes | 68 | this.contadorCandle = contador; |
| 761 | blopes | 69 | this.nomeAtivo = ativoDescricao; |
| 70 | this.dataHora = Date.from(time.atZone(ZoneId.systemDefault()).toInstant()); |
||
| 71 | this.abertura = abertura; |
||
| 72 | this.maxima = topo; |
||
| 73 | this.minima = fundo; |
||
| 74 | this.fechamento = fechamento; |
||
| 75 | this.periodo = periodoCandle; |
||
| 76 | } |
||
| 77 | |||
| 760 | blopes | 78 | @Id |
| 79 | @SequenceGenerator(name = "sq_candle") |
||
| 80 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 81 | @Column(name="seq_candle", nullable=false) |
||
| 82 | public Long getSequencial() { |
||
| 83 | return sequencial; |
||
| 84 | } |
||
| 85 | public void setSequencial(Long sequencial) { |
||
| 86 | this.sequencial = sequencial; |
||
| 87 | } |
||
| 88 | |||
| 89 | @ManyToOne |
||
| 90 | @ForeignKey(name = "fk_candleativo_candle") |
||
| 91 | @JoinColumn(name="seq_ativo", referencedColumnName="seq_ativo") |
||
| 92 | public Ativo getAtivo() { |
||
| 93 | return ativo; |
||
| 94 | } |
||
| 95 | public void setAtivo(Ativo ativo) { |
||
| 96 | this.ativo = ativo; |
||
| 97 | } |
||
| 98 | |||
| 764 | blopes | 99 | @NotNull(message = "Parâmetro obrigatório não preenchido: Contador", groups = {Cadastrar.class, Alterar.class}) |
| 100 | @Column(name="val_contador", nullable=false) |
||
| 101 | public Integer getContadorCandle() { |
||
| 102 | return contadorCandle; |
||
| 103 | } |
||
| 104 | public void setContadorCandle(Integer contadorCandle) { |
||
| 105 | this.contadorCandle = contadorCandle; |
||
| 106 | } |
||
| 107 | |||
| 760 | blopes | 108 | @NotNull(message = "Parâmetro obrigatório não preenchido: Data e hora", groups = {Cadastrar.class, Alterar.class}) |
| 764 | blopes | 109 | @Column(name="dth_datahora", nullable=false) |
| 760 | blopes | 110 | public Date getDataHora() { |
| 111 | return dataHora; |
||
| 112 | } |
||
| 113 | public void setDataHora(Date dataHora) { |
||
| 114 | this.dataHora = dataHora; |
||
| 115 | } |
||
| 764 | blopes | 116 | @Transient |
| 117 | public String getDataHoraFormatada() { |
||
| 118 | return VerificadorUtil.naoEstaNulo(getDataHora())? DataUtils.converterDataComHorarioParaString(getDataHora()) : ""; |
||
| 119 | } |
||
| 120 | @Transient |
||
| 121 | public String getHoraFormatada() { |
||
| 122 | return VerificadorUtil.naoEstaNulo(getDataHora())? DataUtils.converterDataParaStringNoFormato(getDataHora(), "HH:mm:ss") : ""; |
||
| 123 | } |
||
| 760 | blopes | 124 | |
| 125 | @NotNull(message = "Parâmetro obrigatório não preenchido: Preço de abertura", groups = {Cadastrar.class, Alterar.class}) |
||
| 126 | @Column(name="val_abertura", nullable=false) |
||
| 127 | public BigDecimal getAbertura() { |
||
| 128 | return abertura; |
||
| 129 | } |
||
| 130 | public void setAbertura(BigDecimal abertura) { |
||
| 131 | this.abertura = abertura; |
||
| 132 | } |
||
| 133 | |||
| 134 | @NotNull(message = "Parâmetro obrigatório não preenchido: Preço da máxima", groups = {Cadastrar.class, Alterar.class}) |
||
| 135 | @Column(name="val_maxima", nullable=false) |
||
| 136 | public BigDecimal getMaxima() { |
||
| 137 | return maxima; |
||
| 138 | } |
||
| 139 | public void setMaxima(BigDecimal maxima) { |
||
| 140 | this.maxima = maxima; |
||
| 141 | } |
||
| 142 | |||
| 143 | @NotNull(message = "Parâmetro obrigatório não preenchido: Preço da mínima", groups = {Cadastrar.class, Alterar.class}) |
||
| 144 | @Column(name="val_minima", nullable=false) |
||
| 145 | public BigDecimal getMinima() { |
||
| 146 | return minima; |
||
| 147 | } |
||
| 148 | public void setMinima(BigDecimal minima) { |
||
| 149 | this.minima = minima; |
||
| 150 | } |
||
| 151 | |||
| 152 | @NotNull(message = "Parâmetro obrigatório não preenchido: Preço de fechamento", groups = {Cadastrar.class, Alterar.class}) |
||
| 153 | @Column(name="val_fechamento", nullable=false) |
||
| 154 | public BigDecimal getFechamento() { |
||
| 155 | return fechamento; |
||
| 156 | } |
||
| 157 | public void setFechamento(BigDecimal fechamento) { |
||
| 158 | this.fechamento = fechamento; |
||
| 159 | } |
||
| 160 | |||
| 161 | @Column(name="val_volume", nullable=true) |
||
| 162 | public BigDecimal getVolume() { |
||
| 163 | return volume; |
||
| 164 | } |
||
| 165 | public void setVolume(BigDecimal volume) { |
||
| 166 | this.volume = volume; |
||
| 167 | } |
||
| 168 | |||
| 169 | @NotNull(message = "Parâmetro obrigatório não preenchido: Tipo do período do candle", groups = {Cadastrar.class, Alterar.class}) |
||
| 170 | @Column(name="tip_periodo", nullable=false) |
||
| 171 | public String getPeriodo() { |
||
| 172 | return periodo; |
||
| 173 | } |
||
| 174 | public void setPeriodo(String periodo) { |
||
| 175 | this.periodo = periodo; |
||
| 176 | } |
||
| 177 | @Transient |
||
| 178 | public String getTipoPeriodoCandle() { |
||
| 179 | return VerificadorUtil.naoEstaNulo(getPeriodo())? TipoPeriodoCandle.parse(getPeriodo()).getValor() : ""; |
||
| 180 | } |
||
| 181 | |||
| 182 | @Transient |
||
| 183 | public LocalDateTime getDataHoraTime() { |
||
| 184 | return dataHoraTime; |
||
| 185 | } |
||
| 186 | public void setDataHoraTime(LocalDateTime dataHoraTime) { |
||
| 187 | this.dataHoraTime = dataHoraTime; |
||
| 188 | } |
||
| 189 | |||
| 190 | @Transient |
||
| 191 | public Timeframe getPeriodoTimeFramde() { |
||
| 192 | return periodoTimeFramde; |
||
| 193 | } |
||
| 194 | public void setPeriodoTimeFramde(Timeframe periodoTimeFramde) { |
||
| 195 | this.periodoTimeFramde = periodoTimeFramde; |
||
| 196 | } |
||
| 197 | |||
| 761 | blopes | 198 | @Transient |
| 199 | public String getNomeAtivo() { |
||
| 200 | return nomeAtivo; |
||
| 201 | } |
||
| 202 | public void setNomeAtivo(String nomeAtivo) { |
||
| 203 | this.nomeAtivo = nomeAtivo; |
||
| 204 | } |
||
| 205 | |||
| 206 | @Transient |
||
| 763 | blopes | 207 | public Boolean getCandleAnalisado() { |
| 208 | return candleAnalisado; |
||
| 209 | } |
||
| 210 | public void setCandleAnalisado(Boolean candleAnalisado) { |
||
| 211 | this.candleAnalisado = candleAnalisado; |
||
| 212 | } |
||
| 213 | |||
| 760 | blopes | 214 | @Override |
| 215 | public int hashCode() { |
||
| 216 | final int prime = 31; |
||
| 217 | int result = 1; |
||
| 218 | result = prime * result |
||
| 219 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 220 | return result; |
||
| 221 | } |
||
| 222 | |||
| 223 | @Override |
||
| 224 | public boolean equals(Object obj) { |
||
| 225 | if (this == obj) |
||
| 226 | return true; |
||
| 227 | if (obj == null) |
||
| 228 | return false; |
||
| 229 | if (getClass() != obj.getClass()) |
||
| 230 | return false; |
||
| 231 | Candle other = (Candle) obj; |
||
| 232 | if (sequencial == null) { |
||
| 233 | if (other.sequencial != null) |
||
| 234 | return false; |
||
| 235 | } else if (!sequencial.equals(other.sequencial)) |
||
| 236 | return false; |
||
| 237 | return true; |
||
| 238 | } |
||
| 239 | |||
| 762 | blopes | 240 | @Transient |
| 241 | public boolean isCandleComprador() { |
||
| 242 | return BigDecimalUtils.ehMaiorQue(fechamento, abertura); |
||
| 243 | } |
||
| 244 | |||
| 245 | @Transient |
||
| 246 | public boolean isCandleVendedor() { |
||
| 247 | return BigDecimalUtils.ehMenorQue(fechamento, abertura); |
||
| 248 | } |
||
| 249 | |||
| 250 | @Transient |
||
| 251 | public BigDecimal getCorpoAlto() { |
||
| 252 | // return Math.max(abertura.doubleValue(), fechamento.doubleValue()); |
||
| 253 | return BigDecimalUtils.maximo(abertura, fechamento); |
||
| 254 | } |
||
| 255 | |||
| 256 | @Transient |
||
| 257 | public BigDecimal getCorpoBaixo() { |
||
| 258 | // return Math.min(abertura.doubleValue(), fechamento.doubleValue()); |
||
| 259 | return BigDecimalUtils.minimo(abertura, fechamento); |
||
| 260 | } |
||
| 261 | |||
| 760 | blopes | 262 | } |