Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 795 | blopes | 1 | package br.com.kronus.core; |
| 2 | |||
| 3 | import java.beans.Transient; |
||
| 4 | import java.io.Serializable; |
||
| 5 | import java.math.BigDecimal; |
||
| 6 | import java.text.SimpleDateFormat; |
||
| 7 | import java.time.LocalDateTime; |
||
| 8 | import java.time.ZoneId; |
||
| 9 | import java.util.Date; |
||
| 10 | |||
| 11 | public class Candle implements Serializable { |
||
| 12 | |||
| 13 | private static final long serialVersionUID = 1L; |
||
| 14 | |||
| 15 | private Long sequencial; |
||
| 16 | private Integer contadorCandle; |
||
| 17 | private Ativo ativo; |
||
| 18 | private Date dataHora; |
||
| 19 | private BigDecimal abertura; |
||
| 20 | private BigDecimal maxima; |
||
| 21 | private BigDecimal minima; |
||
| 22 | private BigDecimal fechamento; |
||
| 23 | private BigDecimal volume; |
||
| 24 | private String periodo; |
||
| 25 | |||
| 26 | private String nomeAtivo; |
||
| 27 | private LocalDateTime dataHoraTime; |
||
| 28 | private Timeframe periodoTimeFramde; |
||
| 29 | private Boolean candleAnalisado = false; |
||
| 30 | |||
| 31 | public Candle() {} |
||
| 32 | |||
| 33 | public Candle(Ativo ativo, LocalDateTime fimCandle, CandleState situacaoCandle, String periodoCandle) { |
||
| 34 | this.ativo = ativo; |
||
| 35 | this.dataHora = Date.from(situacaoCandle.getLastTickTime().atZone(ZoneId.systemDefault()).toInstant()); |
||
| 36 | this.abertura = situacaoCandle.getAbertura(); |
||
| 37 | this.maxima = situacaoCandle.getMaxima(); |
||
| 38 | this.minima = situacaoCandle.getMinima(); |
||
| 39 | this.fechamento = situacaoCandle.getFechamento(); |
||
| 40 | this.periodo = periodoCandle; |
||
| 41 | } |
||
| 42 | |||
| 43 | public Candle(Integer contador, String ativoDescricao, LocalDateTime time, BigDecimal abertura, BigDecimal topo, BigDecimal fundo, |
||
| 44 | BigDecimal fechamento, String periodoCandle) { |
||
| 45 | this.contadorCandle = contador; |
||
| 46 | this.nomeAtivo = ativoDescricao; |
||
| 47 | this.dataHora = Date.from(time.atZone(ZoneId.systemDefault()).toInstant()); |
||
| 48 | this.abertura = abertura; |
||
| 49 | this.maxima = topo; |
||
| 50 | this.minima = fundo; |
||
| 51 | this.fechamento = fechamento; |
||
| 52 | this.periodo = periodoCandle; |
||
| 53 | } |
||
| 54 | |||
| 55 | public Long getSequencial() { |
||
| 56 | return sequencial; |
||
| 57 | } |
||
| 58 | public void setSequencial(Long sequencial) { |
||
| 59 | this.sequencial = sequencial; |
||
| 60 | } |
||
| 61 | |||
| 62 | public Ativo getAtivo() { |
||
| 63 | return ativo; |
||
| 64 | } |
||
| 65 | public void setAtivo(Ativo ativo) { |
||
| 66 | this.ativo = ativo; |
||
| 67 | } |
||
| 68 | |||
| 69 | public Integer getContadorCandle() { |
||
| 70 | return contadorCandle; |
||
| 71 | } |
||
| 72 | public void setContadorCandle(Integer contadorCandle) { |
||
| 73 | this.contadorCandle = contadorCandle; |
||
| 74 | } |
||
| 75 | |||
| 76 | public Date getDataHora() { |
||
| 77 | return dataHora; |
||
| 78 | } |
||
| 79 | public void setDataHora(Date dataHora) { |
||
| 80 | this.dataHora = dataHora; |
||
| 81 | } |
||
| 82 | public String getDataHoraFormatada() { |
||
| 83 | return VerificadorUtil.naoEstaNulo(getDataHora())? new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(getDataHora()) : ""; |
||
| 84 | } |
||
| 85 | public String getHoraFormatada() { |
||
| 86 | return VerificadorUtil.naoEstaNulo(getDataHora())? new SimpleDateFormat("HH:mm:ss").format(getDataHora()) : ""; |
||
| 87 | } |
||
| 88 | |||
| 89 | public BigDecimal getAbertura() { |
||
| 90 | return abertura; |
||
| 91 | } |
||
| 92 | public void setAbertura(BigDecimal abertura) { |
||
| 93 | this.abertura = abertura; |
||
| 94 | } |
||
| 95 | |||
| 96 | public BigDecimal getMaxima() { |
||
| 97 | return maxima; |
||
| 98 | } |
||
| 99 | public void setMaxima(BigDecimal maxima) { |
||
| 100 | this.maxima = maxima; |
||
| 101 | } |
||
| 102 | |||
| 103 | public BigDecimal getMinima() { |
||
| 104 | return minima; |
||
| 105 | } |
||
| 106 | public void setMinima(BigDecimal minima) { |
||
| 107 | this.minima = minima; |
||
| 108 | } |
||
| 109 | |||
| 110 | public BigDecimal getFechamento() { |
||
| 111 | return fechamento; |
||
| 112 | } |
||
| 113 | public void setFechamento(BigDecimal fechamento) { |
||
| 114 | this.fechamento = fechamento; |
||
| 115 | } |
||
| 116 | |||
| 117 | public BigDecimal getVolume() { |
||
| 118 | return volume; |
||
| 119 | } |
||
| 120 | public void setVolume(BigDecimal volume) { |
||
| 121 | this.volume = volume; |
||
| 122 | } |
||
| 123 | |||
| 124 | public String getPeriodo() { |
||
| 125 | return periodo; |
||
| 126 | } |
||
| 127 | public void setPeriodo(String periodo) { |
||
| 128 | this.periodo = periodo; |
||
| 129 | } |
||
| 130 | @Transient |
||
| 131 | public String getTipoPeriodoCandle() { |
||
| 132 | return VerificadorUtil.naoEstaNulo(getPeriodo())? TipoPeriodoCandle.parse(getPeriodo()).getValor() : ""; |
||
| 133 | } |
||
| 134 | |||
| 135 | @Transient |
||
| 136 | public LocalDateTime getDataHoraTime() { |
||
| 137 | return dataHoraTime; |
||
| 138 | } |
||
| 139 | public void setDataHoraTime(LocalDateTime dataHoraTime) { |
||
| 140 | this.dataHoraTime = dataHoraTime; |
||
| 141 | } |
||
| 142 | |||
| 143 | @Transient |
||
| 144 | public Timeframe getPeriodoTimeFramde() { |
||
| 145 | return periodoTimeFramde; |
||
| 146 | } |
||
| 147 | public void setPeriodoTimeFramde(Timeframe periodoTimeFramde) { |
||
| 148 | this.periodoTimeFramde = periodoTimeFramde; |
||
| 149 | } |
||
| 150 | |||
| 151 | @Transient |
||
| 152 | public String getNomeAtivo() { |
||
| 153 | return nomeAtivo; |
||
| 154 | } |
||
| 155 | public void setNomeAtivo(String nomeAtivo) { |
||
| 156 | this.nomeAtivo = nomeAtivo; |
||
| 157 | } |
||
| 158 | |||
| 159 | @Transient |
||
| 160 | public Boolean getCandleAnalisado() { |
||
| 161 | return candleAnalisado; |
||
| 162 | } |
||
| 163 | public void setCandleAnalisado(Boolean candleAnalisado) { |
||
| 164 | this.candleAnalisado = candleAnalisado; |
||
| 165 | } |
||
| 166 | |||
| 167 | @Override |
||
| 168 | public int hashCode() { |
||
| 169 | final int prime = 31; |
||
| 170 | int result = 1; |
||
| 171 | result = prime * result |
||
| 172 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 173 | return result; |
||
| 174 | } |
||
| 175 | |||
| 176 | @Override |
||
| 177 | public boolean equals(Object obj) { |
||
| 178 | if (this == obj) |
||
| 179 | return true; |
||
| 180 | if (obj == null) |
||
| 181 | return false; |
||
| 182 | if (getClass() != obj.getClass()) |
||
| 183 | return false; |
||
| 184 | Candle other = (Candle) obj; |
||
| 185 | if (sequencial == null) { |
||
| 186 | if (other.sequencial != null) |
||
| 187 | return false; |
||
| 188 | } else if (!sequencial.equals(other.sequencial)) |
||
| 189 | return false; |
||
| 190 | return true; |
||
| 191 | } |
||
| 192 | |||
| 193 | @Transient |
||
| 194 | public boolean isCandleComprador() { |
||
| 195 | return BigDecimalUtils.ehMaiorQue(fechamento, abertura); |
||
| 196 | } |
||
| 197 | |||
| 198 | @Transient |
||
| 199 | public boolean isCandleVendedor() { |
||
| 200 | return BigDecimalUtils.ehMenorQue(fechamento, abertura); |
||
| 201 | } |
||
| 202 | |||
| 203 | @Transient |
||
| 204 | public BigDecimal getCorpoAlto() { |
||
| 205 | // return Math.max(abertura.doubleValue(), fechamento.doubleValue()); |
||
| 206 | return BigDecimalUtils.maximo(abertura, fechamento); |
||
| 207 | } |
||
| 208 | |||
| 209 | @Transient |
||
| 210 | public BigDecimal getCorpoBaixo() { |
||
| 211 | // return Math.min(abertura.doubleValue(), fechamento.doubleValue()); |
||
| 212 | return BigDecimalUtils.minimo(abertura, fechamento); |
||
| 213 | } |
||
| 214 | |||
| 215 | } |