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