Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 783 | blopes | 1 | package br.com.sl.controller; |
| 2 | |||
| 3 | import javax.inject.Inject; |
||
| 4 | import javax.inject.Named; |
||
| 5 | |||
| 6 | import org.primefaces.event.FileUploadEvent; |
||
| 7 | import org.primefaces.model.file.UploadedFile; |
||
| 8 | import org.primefaces.model.file.UploadedFiles; |
||
| 9 | import org.springframework.context.annotation.Scope; |
||
| 10 | |||
| 11 | import br.com.ec.core.generic.GenericService; |
||
| 12 | import br.com.ec.web.exception.VerificadorLancamentoException; |
||
| 13 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 14 | import br.com.ec.web.generic.AbstractBean; |
||
| 15 | import br.com.ec.web.message.LancadorMensagem; |
||
| 16 | import br.com.sl.domain.dto.SinaisResultadoDTO; |
||
| 17 | import br.com.sl.domain.service.AnalisadorPadroesService; |
||
| 18 | |||
| 19 | @Named |
||
| 20 | @Scope("view") |
||
| 21 | public class VerificadorSinaisBean extends AbstractBean<SinaisResultadoDTO> { |
||
| 22 | |||
| 23 | private UploadedFiles arquivos; |
||
| 24 | |||
| 25 | private AnalisadorPadroesService analisadorPadroesService; |
||
| 26 | |||
| 27 | @Inject |
||
| 28 | public VerificadorSinaisBean(AnalisadorPadroesService analisadorPadroesService) { |
||
| 29 | this.analisadorPadroesService = analisadorPadroesService; |
||
| 30 | } |
||
| 31 | |||
| 32 | @Override |
||
| 33 | public void preCarregamento() { |
||
| 34 | limparEntidade(); |
||
| 35 | } |
||
| 36 | |||
| 37 | @Override |
||
| 38 | public SinaisResultadoDTO getId() { |
||
| 39 | return null; |
||
| 40 | } |
||
| 41 | |||
| 42 | @Override |
||
| 43 | public GenericService<SinaisResultadoDTO> getService() { |
||
| 44 | return null; |
||
| 45 | } |
||
| 46 | |||
| 47 | @Override |
||
| 48 | public void limparEntidade() { |
||
| 49 | setEntidade(new SinaisResultadoDTO()); |
||
| 50 | setArquivos(new UploadedFiles()); |
||
| 51 | } |
||
| 52 | |||
| 53 | public UploadedFiles getArquivos() { |
||
| 54 | return arquivos; |
||
| 55 | } |
||
| 56 | public void setArquivos(UploadedFiles arquivos) { |
||
| 57 | this.arquivos = arquivos; |
||
| 58 | } |
||
| 59 | |||
| 60 | public void analisarViaUpload() { |
||
| 61 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 62 | public void execute() { |
||
| 63 | analisadorPadroesService.analisarPadroesViaArquivos(getEntidade(), getArquivos()); |
||
| 64 | LancadorMensagem.lancarSucesso("DADOS ANALISADOS COM SUCESSO!"); |
||
| 65 | } |
||
| 66 | }); |
||
| 67 | } |
||
| 68 | |||
| 69 | } |
||
| 70 | |||
| 71 | |||
| 72 | /* |
||
| 73 | private RoboOperadorService roboOperadorService; |
||
| 74 | |||
| 75 | private String tipoFonteSelecionada; |
||
| 76 | private Integer contadorCandleParaVerificar; |
||
| 77 | private List<String> logs; |
||
| 78 | |||
| 79 | private List<PadraoGatilho> padroesEmAberto; |
||
| 80 | private Integer contadorUltimoCandle; |
||
| 81 | |||
| 82 | private List<PadraoGatilho> padroes; |
||
| 83 | private List<PadraoGatilho> padroesComG3; // completos (G3 != null) |
||
| 84 | private List<PadraoGatilho> padroesAteG2; // parciais (G2 != null && G3 == null) |
||
| 85 | |||
| 86 | private List<SinalTradeGatilho3> sinaisTradeGatilho3; |
||
| 87 | private List<ResultadoEstrategiaGatilho3> resultados; |
||
| 88 | |||
| 89 | |||
| 90 | @Inject |
||
| 91 | public VerificadorSinaisBean(RoboOperadorService roboOperadorService) { |
||
| 92 | this.roboOperadorService = roboOperadorService; |
||
| 93 | } |
||
| 94 | |||
| 95 | @Override |
||
| 96 | public void preCarregamento() { |
||
| 97 | limparEntidade(); |
||
| 98 | getEntidade().setRodando(roboOperadorService.isRodando()); |
||
| 99 | } |
||
| 100 | |||
| 101 | @Override |
||
| 102 | public void limparEntidade() { |
||
| 103 | setEntidade(new RoboDTO()); |
||
| 104 | setPadroes(new ArrayList<PadraoGatilho>()); |
||
| 105 | setPadroesComG3(new ArrayList<PadraoGatilho>()); |
||
| 106 | setPadroesAteG2(new ArrayList<PadraoGatilho>()); |
||
| 107 | setSinaisTradeGatilho3(new ArrayList<SinalTradeGatilho3>()); |
||
| 108 | setResultados(new ArrayList<ResultadoEstrategiaGatilho3>()); |
||
| 109 | setTipoFonteSelecionada(TipoFonteDadosProfit.TEMPO_REAL.getValor()); |
||
| 110 | setContadorCandleParaVerificar(0); |
||
| 111 | } |
||
| 112 | |||
| 113 | @Override |
||
| 114 | public GenericService<RoboDTO> getService() { |
||
| 115 | return roboOperadorService; |
||
| 116 | } |
||
| 117 | |||
| 118 | @Override |
||
| 119 | public RoboDTO getEntidade() { |
||
| 120 | return entidade; |
||
| 121 | } |
||
| 122 | |||
| 123 | @Override |
||
| 124 | public RoboDTO getId() { |
||
| 125 | return getEntidade(); |
||
| 126 | } |
||
| 127 | |||
| 128 | public List<PadraoGatilho> getPadroes() { |
||
| 129 | return padroes; |
||
| 130 | } |
||
| 131 | public void setPadroes(List<PadraoGatilho> padroes) { |
||
| 132 | this.padroes = padroes; |
||
| 133 | } |
||
| 134 | |||
| 135 | public List<SinalTradeGatilho3> getSinaisTradeGatilho3() { |
||
| 136 | return sinaisTradeGatilho3; |
||
| 137 | } |
||
| 138 | public void setSinaisTradeGatilho3(List<SinalTradeGatilho3> sinaisTradeGatilho3) { |
||
| 139 | this.sinaisTradeGatilho3 = sinaisTradeGatilho3; |
||
| 140 | } |
||
| 141 | |||
| 142 | public List<ResultadoEstrategiaGatilho3> getResultados() { |
||
| 143 | return resultados; |
||
| 144 | } |
||
| 145 | public void setResultados(List<ResultadoEstrategiaGatilho3> resultados) { |
||
| 146 | this.resultados = resultados; |
||
| 147 | } |
||
| 148 | |||
| 149 | public List<PadraoGatilho> getPadroesComG3() { |
||
| 150 | return padroesComG3; |
||
| 151 | } |
||
| 152 | public void setPadroesComG3(List<PadraoGatilho> padroesComG3) { |
||
| 153 | this.padroesComG3 = padroesComG3; |
||
| 154 | } |
||
| 155 | |||
| 156 | public List<PadraoGatilho> getPadroesAteG2() { |
||
| 157 | return padroesAteG2; |
||
| 158 | } |
||
| 159 | public void setPadroesAteG2(List<PadraoGatilho> padroesAteG2) { |
||
| 160 | this.padroesAteG2 = padroesAteG2; |
||
| 161 | } |
||
| 162 | |||
| 163 | public String getTipoFonteSelecionada() { |
||
| 164 | return tipoFonteSelecionada; |
||
| 165 | } |
||
| 166 | public void setTipoFonteSelecionada(String tipoFonteSelecionada) { |
||
| 167 | this.tipoFonteSelecionada = tipoFonteSelecionada; |
||
| 168 | } |
||
| 169 | |||
| 170 | public TipoFonteDadosProfit[] getTiposFonteDadosProfit() { |
||
| 171 | return TipoFonteDadosProfit.values(); |
||
| 172 | } |
||
| 173 | |||
| 174 | public List<String> getLogs() { |
||
| 175 | return logs; |
||
| 176 | } |
||
| 177 | public void setLogs(List<String> logs) { |
||
| 178 | this.logs = logs; |
||
| 179 | } |
||
| 180 | |||
| 181 | public String getLogsBacktestAsText() { |
||
| 182 | if (logs == null || logs.isEmpty()) return ""; |
||
| 183 | return String.join("\n", logs); |
||
| 184 | } |
||
| 185 | |||
| 186 | public Integer getContadorCandleParaVerificar() { |
||
| 187 | return contadorCandleParaVerificar; |
||
| 188 | } |
||
| 189 | public void setContadorCandleParaVerificar(Integer contadorCandleParaVerificar) { |
||
| 190 | this.contadorCandleParaVerificar = contadorCandleParaVerificar; |
||
| 191 | } |
||
| 192 | |||
| 193 | public void iniciar() { |
||
| 194 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 195 | public void execute() { |
||
| 196 | roboOperadorService.iniciarOperacao(getTipoFonteSelecionada(), getContadorCandleParaVerificar()); |
||
| 197 | setEntidade(roboOperadorService.statusRobo()); |
||
| 198 | LancadorMensagem.lancarSucesso("ROBÔ INICIADO COM SUCESSO!"); |
||
| 199 | } |
||
| 200 | }); |
||
| 201 | } |
||
| 202 | |||
| 203 | public void parar() { |
||
| 204 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 205 | public void execute() { |
||
| 206 | roboOperadorService.pararOperacao(); |
||
| 207 | setEntidade(roboOperadorService.statusRobo()); |
||
| 208 | LancadorMensagem.lancarSucesso("ROBÔ PARADO COM SUCESSO!"); |
||
| 209 | } |
||
| 210 | }); |
||
| 211 | } |
||
| 212 | |||
| 213 | public void preencherOutrosPadroes() { |
||
| 214 | padroesComG3 = padroes.stream() |
||
| 215 | .filter(p -> p.getTipoPadrao() == TipoPadrao.COMPLETO_G3) |
||
| 216 | .collect(Collectors.toList()); |
||
| 217 | padroesComG3 = inverterLista(padroesComG3); |
||
| 218 | |||
| 219 | padroesAteG2 = padroes.stream() |
||
| 220 | .filter(p -> p.getTipoPadrao() == TipoPadrao.PARCIAL_G2) |
||
| 221 | .collect(Collectors.toList()); |
||
| 222 | padroesAteG2 = inverterLista(padroesAteG2); |
||
| 223 | } |
||
| 224 | |||
| 225 | public static List<PadraoGatilho> inverterLista(List<PadraoGatilho> candles) { |
||
| 226 | List<PadraoGatilho> invertida = new ArrayList<>(candles); |
||
| 227 | Collections.reverse(invertida); |
||
| 228 | return invertida; |
||
| 229 | } |
||
| 230 | |||
| 231 | public void atualizarStatus() { |
||
| 232 | setEntidade(roboOperadorService.statusRobo()); |
||
| 233 | if (VerificadorUtil.naoEstaNuloOuVazio(getEntidade().getPadroes())) { |
||
| 234 | if (getEntidade().getPadroes().size() != getPadroes().size()) { |
||
| 235 | AlertaPadraoService.novoAlerta("NOVO PADRÃO IDENTIFICADO!"); |
||
| 236 | PrimeFaces.current().executeScript("playAlertaAgressivo();"); |
||
| 237 | } |
||
| 238 | setPadroes(getEntidade().getPadroes()); |
||
| 239 | setLogs(getEntidade().getLogs()); |
||
| 240 | preencherOutrosPadroes(); |
||
| 241 | setSinaisTradeGatilho3(getEntidade().getSinaisTradeGatilho3()); |
||
| 242 | setResultados(getEntidade().getResultados()); |
||
| 243 | } |
||
| 244 | verificarNovosPadroes(); |
||
| 245 | } |
||
| 246 | |||
| 247 | public void verificarNovosPadroes() { |
||
| 248 | List<String> alertas = AlertaPadraoService.consumirAlertas(); |
||
| 249 | |||
| 250 | if (!alertas.isEmpty()) { |
||
| 251 | for (String msg : alertas) { |
||
| 252 | FacesMessage facesMessage = new FacesMessage( |
||
| 253 | FacesMessage.SEVERITY_INFO, |
||
| 254 | "Novo padrão identificado", |
||
| 255 | msg |
||
| 256 | ); |
||
| 257 | javax.faces.context.FacesContext.getCurrentInstance() |
||
| 258 | .addMessage(null, facesMessage); |
||
| 259 | } |
||
| 260 | |||
| 261 | // Toca o som no cliente |
||
| 262 | PrimeFaces.current().executeScript("playBeepPadrao();"); |
||
| 263 | // Se estiver em PF antigo: |
||
| 264 | // RequestContext.getCurrentInstance().execute("playBeepPadrao();"); |
||
| 265 | } |
||
| 266 | } |
||
| 267 | |||
| 268 | public void verificarCandle() { |
||
| 269 | |||
| 270 | } |
||
| 271 | } |
||
| 272 | */ |