Rev 770 | Rev 776 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 761 | blopes | 1 | package br.com.sl.controller; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 764 | blopes | 4 | import java.util.ArrayList; |
| 5 | import java.util.Collections; |
||
| 6 | import java.util.List; |
||
| 7 | import java.util.stream.Collectors; |
||
| 761 | blopes | 8 | |
| 764 | blopes | 9 | import javax.faces.application.FacesMessage; |
| 761 | blopes | 10 | import javax.inject.Inject; |
| 11 | import javax.inject.Named; |
||
| 12 | |||
| 764 | blopes | 13 | import org.primefaces.PrimeFaces; |
| 761 | blopes | 14 | import org.springframework.context.annotation.Scope; |
| 15 | |||
| 16 | import br.com.ec.core.generic.GenericService; |
||
| 764 | blopes | 17 | import br.com.ec.core.util.VerificadorUtil; |
| 761 | blopes | 18 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 19 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 20 | import br.com.ec.web.generic.AbstractBean; |
||
| 21 | import br.com.ec.web.message.LancadorMensagem; |
||
| 764 | blopes | 22 | import br.com.kronus.core.PadraoGatilho; |
| 767 | blopes | 23 | import br.com.kronus.strategy.ResultadoEstrategiaGatilho3; |
| 761 | blopes | 24 | import br.com.sl.domain.dto.RoboDTO; |
| 764 | blopes | 25 | import br.com.sl.domain.dto.robo.AlertaPadraoService; |
| 767 | blopes | 26 | import br.com.sl.domain.dto.robo.SinalTradeGatilho3; |
| 27 | import br.com.sl.domain.model.tipos.TipoFonteDadosProfit; |
||
| 761 | blopes | 28 | import br.com.sl.domain.service.RoboOperadorService; |
| 29 | |||
| 30 | @Named |
||
| 31 | @Scope("view") |
||
| 32 | public class RoboBean extends AbstractBean<RoboDTO> implements Serializable { |
||
| 33 | |||
| 34 | private RoboOperadorService roboOperadorService; |
||
| 35 | |||
| 771 | blopes | 36 | private String tipoFonteSelecionada; |
| 37 | |||
| 764 | blopes | 38 | private List<PadraoGatilho> padroesEmAberto; |
| 765 | blopes | 39 | private Integer contadorUltimoCandle; |
| 764 | blopes | 40 | |
| 41 | private List<PadraoGatilho> padroes; |
||
| 42 | private List<PadraoGatilho> padroesComG3; // completos (G3 != null) |
||
| 43 | private List<PadraoGatilho> padroesAteG2; // parciais (G2 != null && G3 == null) |
||
| 767 | blopes | 44 | |
| 45 | private List<SinalTradeGatilho3> sinaisTradeGatilho3; |
||
| 46 | private List<ResultadoEstrategiaGatilho3> resultados; |
||
| 764 | blopes | 47 | |
| 761 | blopes | 48 | @Inject |
| 49 | public RoboBean(RoboOperadorService roboOperadorService) { |
||
| 50 | this.roboOperadorService = roboOperadorService; |
||
| 51 | } |
||
| 52 | |||
| 53 | @Override |
||
| 54 | public void preCarregamento() { |
||
| 55 | limparEntidade(); |
||
| 56 | getEntidade().setRodando(roboOperadorService.isRodando()); |
||
| 57 | } |
||
| 58 | |||
| 59 | @Override |
||
| 60 | public void limparEntidade() { |
||
| 61 | setEntidade(new RoboDTO()); |
||
| 764 | blopes | 62 | setPadroes(new ArrayList<PadraoGatilho>()); |
| 63 | setPadroesComG3(new ArrayList<PadraoGatilho>()); |
||
| 64 | setPadroesAteG2(new ArrayList<PadraoGatilho>()); |
||
| 767 | blopes | 65 | setSinaisTradeGatilho3(new ArrayList<SinalTradeGatilho3>()); |
| 66 | setResultados(new ArrayList<ResultadoEstrategiaGatilho3>()); |
||
| 771 | blopes | 67 | setTipoFonteSelecionada(TipoFonteDadosProfit.TEMPO_REAL.getValor()); |
| 761 | blopes | 68 | } |
| 69 | |||
| 70 | @Override |
||
| 71 | public GenericService<RoboDTO> getService() { |
||
| 72 | return roboOperadorService; |
||
| 73 | } |
||
| 74 | |||
| 75 | @Override |
||
| 76 | public RoboDTO getEntidade() { |
||
| 77 | return entidade; |
||
| 78 | } |
||
| 79 | |||
| 80 | @Override |
||
| 81 | public RoboDTO getId() { |
||
| 82 | return getEntidade(); |
||
| 83 | } |
||
| 84 | |||
| 764 | blopes | 85 | public List<PadraoGatilho> getPadroes() { |
| 86 | return padroes; |
||
| 87 | } |
||
| 88 | public void setPadroes(List<PadraoGatilho> padroes) { |
||
| 89 | this.padroes = padroes; |
||
| 90 | } |
||
| 91 | |||
| 767 | blopes | 92 | public List<SinalTradeGatilho3> getSinaisTradeGatilho3() { |
| 93 | return sinaisTradeGatilho3; |
||
| 94 | } |
||
| 95 | public void setSinaisTradeGatilho3(List<SinalTradeGatilho3> sinaisTradeGatilho3) { |
||
| 96 | this.sinaisTradeGatilho3 = sinaisTradeGatilho3; |
||
| 97 | } |
||
| 98 | |||
| 99 | public List<ResultadoEstrategiaGatilho3> getResultados() { |
||
| 100 | return resultados; |
||
| 101 | } |
||
| 102 | public void setResultados(List<ResultadoEstrategiaGatilho3> resultados) { |
||
| 103 | this.resultados = resultados; |
||
| 104 | } |
||
| 105 | |||
| 764 | blopes | 106 | public List<PadraoGatilho> getPadroesComG3() { |
| 107 | return padroesComG3; |
||
| 108 | } |
||
| 109 | public void setPadroesComG3(List<PadraoGatilho> padroesComG3) { |
||
| 110 | this.padroesComG3 = padroesComG3; |
||
| 111 | } |
||
| 112 | |||
| 113 | public List<PadraoGatilho> getPadroesAteG2() { |
||
| 114 | return padroesAteG2; |
||
| 115 | } |
||
| 116 | public void setPadroesAteG2(List<PadraoGatilho> padroesAteG2) { |
||
| 117 | this.padroesAteG2 = padroesAteG2; |
||
| 118 | } |
||
| 119 | |||
| 771 | blopes | 120 | public String getTipoFonteSelecionada() { |
| 121 | return tipoFonteSelecionada; |
||
| 122 | } |
||
| 123 | public void setTipoFonteSelecionada(String tipoFonteSelecionada) { |
||
| 124 | this.tipoFonteSelecionada = tipoFonteSelecionada; |
||
| 125 | } |
||
| 126 | |||
| 127 | public TipoFonteDadosProfit[] getTiposFonteDadosProfit() { |
||
| 128 | return TipoFonteDadosProfit.values(); |
||
| 129 | } |
||
| 130 | |||
| 761 | blopes | 131 | public void iniciar() { |
| 132 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 133 | public void execute() { |
||
| 771 | blopes | 134 | roboOperadorService.iniciarOperacao(getTipoFonteSelecionada()); |
| 761 | blopes | 135 | setEntidade(roboOperadorService.statusRobo()); |
| 136 | LancadorMensagem.lancarSucesso("ROBÔ INICIADO COM SUCESSO!"); |
||
| 137 | } |
||
| 138 | }); |
||
| 139 | } |
||
| 140 | |||
| 141 | public void parar() { |
||
| 142 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 143 | public void execute() { |
||
| 144 | roboOperadorService.pararOperacao(); |
||
| 145 | setEntidade(roboOperadorService.statusRobo()); |
||
| 146 | LancadorMensagem.lancarSucesso("ROBÔ PARADO COM SUCESSO!"); |
||
| 147 | } |
||
| 148 | }); |
||
| 149 | } |
||
| 764 | blopes | 150 | |
| 151 | public void preencherOutrosPadroes() { |
||
| 770 | blopes | 152 | padroesComG3 = padroes.stream() |
| 764 | blopes | 153 | .filter(p -> p.getGatilho2() != null && p.getGatilho3() != null) |
| 154 | .collect(Collectors.toList()); |
||
| 770 | blopes | 155 | padroesComG3 = inverterLista(padroesComG3); |
| 761 | blopes | 156 | |
| 764 | blopes | 157 | padroesAteG2 = padroes.stream() |
| 158 | .filter(p -> p.getGatilho2() != null && p.getGatilho3() == null) |
||
| 159 | .collect(Collectors.toList()); |
||
| 770 | blopes | 160 | padroesAteG2 = inverterLista(padroesAteG2); |
| 764 | blopes | 161 | } |
| 162 | |||
| 163 | public static List<PadraoGatilho> inverterLista(List<PadraoGatilho> candles) { |
||
| 164 | List<PadraoGatilho> invertida = new ArrayList<>(candles); |
||
| 165 | Collections.reverse(invertida); |
||
| 166 | return invertida; |
||
| 167 | } |
||
| 168 | |||
| 761 | blopes | 169 | public void atualizarStatus() { |
| 170 | setEntidade(roboOperadorService.statusRobo()); |
||
| 764 | blopes | 171 | if (VerificadorUtil.naoEstaNuloOuVazio(getEntidade().getPadroes())) { |
| 172 | if (getEntidade().getPadroes().size() != getPadroes().size()) { |
||
| 173 | AlertaPadraoService.novoAlerta("NOVO PADRÃO IDENTIFICADO!"); |
||
| 174 | PrimeFaces.current().executeScript("playAlertaAgressivo();"); |
||
| 175 | } |
||
| 176 | setPadroes(getEntidade().getPadroes()); |
||
| 177 | preencherOutrosPadroes(); |
||
| 767 | blopes | 178 | setSinaisTradeGatilho3(getEntidade().getSinaisTradeGatilho3()); |
| 179 | setResultados(getEntidade().getResultados()); |
||
| 764 | blopes | 180 | } |
| 181 | verificarNovosPadroes(); |
||
| 761 | blopes | 182 | } |
| 764 | blopes | 183 | |
| 184 | public void verificarNovosPadroes() { |
||
| 185 | List<String> alertas = AlertaPadraoService.consumirAlertas(); |
||
| 761 | blopes | 186 | |
| 764 | blopes | 187 | if (!alertas.isEmpty()) { |
| 188 | for (String msg : alertas) { |
||
| 189 | FacesMessage facesMessage = new FacesMessage( |
||
| 190 | FacesMessage.SEVERITY_INFO, |
||
| 191 | "Novo padrão identificado", |
||
| 192 | msg |
||
| 193 | ); |
||
| 194 | javax.faces.context.FacesContext.getCurrentInstance() |
||
| 195 | .addMessage(null, facesMessage); |
||
| 196 | } |
||
| 197 | |||
| 198 | // Toca o som no cliente |
||
| 199 | PrimeFaces.current().executeScript("playBeepPadrao();"); |
||
| 200 | // Se estiver em PF antigo: |
||
| 201 | // RequestContext.getCurrentInstance().execute("playBeepPadrao();"); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | |||
| 761 | blopes | 205 | } |