Rev 765 | Rev 770 | 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 | |||
| 767 | blopes | 36 | // private TipoFonteDadosProfit tipoFonteSelecionada = TipoFonteDadosProfit.HISTORICO; |
| 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>()); |
||
| 761 | blopes | 67 | } |
| 68 | |||
| 69 | @Override |
||
| 70 | public GenericService<RoboDTO> getService() { |
||
| 71 | return roboOperadorService; |
||
| 72 | } |
||
| 73 | |||
| 74 | @Override |
||
| 75 | public RoboDTO getEntidade() { |
||
| 76 | return entidade; |
||
| 77 | } |
||
| 78 | |||
| 79 | @Override |
||
| 80 | public RoboDTO getId() { |
||
| 81 | return getEntidade(); |
||
| 82 | } |
||
| 83 | |||
| 764 | blopes | 84 | public List<PadraoGatilho> getPadroes() { |
| 85 | return padroes; |
||
| 86 | } |
||
| 87 | public void setPadroes(List<PadraoGatilho> padroes) { |
||
| 88 | this.padroes = padroes; |
||
| 89 | } |
||
| 90 | |||
| 767 | blopes | 91 | public List<SinalTradeGatilho3> getSinaisTradeGatilho3() { |
| 92 | return sinaisTradeGatilho3; |
||
| 93 | } |
||
| 94 | public void setSinaisTradeGatilho3(List<SinalTradeGatilho3> sinaisTradeGatilho3) { |
||
| 95 | this.sinaisTradeGatilho3 = sinaisTradeGatilho3; |
||
| 96 | } |
||
| 97 | |||
| 98 | public List<ResultadoEstrategiaGatilho3> getResultados() { |
||
| 99 | return resultados; |
||
| 100 | } |
||
| 101 | public void setResultados(List<ResultadoEstrategiaGatilho3> resultados) { |
||
| 102 | this.resultados = resultados; |
||
| 103 | } |
||
| 104 | |||
| 764 | blopes | 105 | public List<PadraoGatilho> getPadroesComG3() { |
| 106 | return padroesComG3; |
||
| 107 | } |
||
| 108 | public void setPadroesComG3(List<PadraoGatilho> padroesComG3) { |
||
| 109 | this.padroesComG3 = padroesComG3; |
||
| 110 | } |
||
| 111 | |||
| 112 | public List<PadraoGatilho> getPadroesAteG2() { |
||
| 113 | return padroesAteG2; |
||
| 114 | } |
||
| 115 | public void setPadroesAteG2(List<PadraoGatilho> padroesAteG2) { |
||
| 116 | this.padroesAteG2 = padroesAteG2; |
||
| 117 | } |
||
| 118 | |||
| 761 | blopes | 119 | public void iniciar() { |
| 120 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 121 | public void execute() { |
||
| 122 | // ANALISAR POR HISTÓRICO |
||
| 767 | blopes | 123 | getEntidade().setAnalisarPorHistoricoArquivo(false); |
| 761 | blopes | 124 | |
| 125 | roboOperadorService.iniciarOperacao(getEntidade().getAnalisarPorHistoricoArquivo()); |
||
| 126 | setEntidade(roboOperadorService.statusRobo()); |
||
| 127 | LancadorMensagem.lancarSucesso("ROBÔ INICIADO COM SUCESSO!"); |
||
| 128 | } |
||
| 129 | }); |
||
| 130 | } |
||
| 131 | |||
| 132 | public void parar() { |
||
| 133 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 134 | public void execute() { |
||
| 135 | roboOperadorService.pararOperacao(); |
||
| 136 | setEntidade(roboOperadorService.statusRobo()); |
||
| 137 | LancadorMensagem.lancarSucesso("ROBÔ PARADO COM SUCESSO!"); |
||
| 138 | } |
||
| 139 | }); |
||
| 140 | } |
||
| 764 | blopes | 141 | |
| 142 | public void preencherOutrosPadroes() { |
||
| 143 | padroesComG3 = padroes.stream() |
||
| 144 | .filter(p -> p.getGatilho2() != null && p.getGatilho3() != null) |
||
| 145 | .collect(Collectors.toList()); |
||
| 146 | inverterLista(padroesComG3); |
||
| 761 | blopes | 147 | |
| 764 | blopes | 148 | padroesAteG2 = padroes.stream() |
| 149 | .filter(p -> p.getGatilho2() != null && p.getGatilho3() == null) |
||
| 150 | .collect(Collectors.toList()); |
||
| 151 | inverterLista(padroesAteG2); |
||
| 152 | } |
||
| 153 | |||
| 154 | public static List<PadraoGatilho> inverterLista(List<PadraoGatilho> candles) { |
||
| 155 | List<PadraoGatilho> invertida = new ArrayList<>(candles); |
||
| 156 | Collections.reverse(invertida); |
||
| 157 | return invertida; |
||
| 158 | } |
||
| 159 | |||
| 761 | blopes | 160 | public void atualizarStatus() { |
| 161 | setEntidade(roboOperadorService.statusRobo()); |
||
| 764 | blopes | 162 | if (VerificadorUtil.naoEstaNuloOuVazio(getEntidade().getPadroes())) { |
| 163 | if (getEntidade().getPadroes().size() != getPadroes().size()) { |
||
| 164 | AlertaPadraoService.novoAlerta("NOVO PADRÃO IDENTIFICADO!"); |
||
| 165 | PrimeFaces.current().executeScript("playAlertaAgressivo();"); |
||
| 166 | } |
||
| 167 | setPadroes(getEntidade().getPadroes()); |
||
| 168 | preencherOutrosPadroes(); |
||
| 767 | blopes | 169 | setSinaisTradeGatilho3(getEntidade().getSinaisTradeGatilho3()); |
| 170 | setResultados(getEntidade().getResultados()); |
||
| 764 | blopes | 171 | } |
| 172 | verificarNovosPadroes(); |
||
| 761 | blopes | 173 | } |
| 764 | blopes | 174 | |
| 175 | public void verificarNovosPadroes() { |
||
| 176 | List<String> alertas = AlertaPadraoService.consumirAlertas(); |
||
| 761 | blopes | 177 | |
| 764 | blopes | 178 | if (!alertas.isEmpty()) { |
| 179 | for (String msg : alertas) { |
||
| 180 | FacesMessage facesMessage = new FacesMessage( |
||
| 181 | FacesMessage.SEVERITY_INFO, |
||
| 182 | "Novo padrão identificado", |
||
| 183 | msg |
||
| 184 | ); |
||
| 185 | javax.faces.context.FacesContext.getCurrentInstance() |
||
| 186 | .addMessage(null, facesMessage); |
||
| 187 | } |
||
| 188 | |||
| 189 | // Toca o som no cliente |
||
| 190 | PrimeFaces.current().executeScript("playBeepPadrao();"); |
||
| 191 | // Se estiver em PF antigo: |
||
| 192 | // RequestContext.getCurrentInstance().execute("playBeepPadrao();"); |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 761 | blopes | 196 | } |