Subversion Repositories Integrator Subversion

Rev

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