Rev 771 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 771 | Rev 776 | ||
|---|---|---|---|
| Line 18... | Line 18... | ||
| 18 | import br.com.ec.web.exception.VerificadorLancamentoException; |
18 | import br.com.ec.web.exception.VerificadorLancamentoException; |
| 19 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
19 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
| 20 | import br.com.ec.web.generic.AbstractBean; |
20 | import br.com.ec.web.generic.AbstractBean; |
| 21 | import br.com.ec.web.message.LancadorMensagem; |
21 | import br.com.ec.web.message.LancadorMensagem; |
| 22 | import br.com.kronus.core.PadraoGatilho; |
22 | import br.com.kronus.core.PadraoGatilho; |
| - | 23 | import br.com.kronus.core.PadraoGatilho.TipoPadrao; |
|
| 23 | import br.com.kronus.strategy.ResultadoEstrategiaGatilho3; |
24 | import br.com.kronus.strategy.ResultadoEstrategiaGatilho3; |
| 24 | import br.com.sl.domain.dto.RoboDTO; |
25 | import br.com.sl.domain.dto.RoboDTO; |
| 25 | import br.com.sl.domain.dto.robo.AlertaPadraoService; |
26 | import br.com.sl.domain.dto.robo.AlertaPadraoService; |
| 26 | import br.com.sl.domain.dto.robo.SinalTradeGatilho3; |
27 | import br.com.sl.domain.dto.robo.SinalTradeGatilho3; |
| 27 | import br.com.sl.domain.model.tipos.TipoFonteDadosProfit; |
28 | import br.com.sl.domain.model.tipos.TipoFonteDadosProfit; |
| Line 32... | Line 33... | ||
| 32 | public class RoboBean extends AbstractBean<RoboDTO> implements Serializable { |
33 | public class RoboBean extends AbstractBean<RoboDTO> implements Serializable { |
| 33 | 34 | ||
| 34 | private RoboOperadorService roboOperadorService; |
35 | private RoboOperadorService roboOperadorService; |
| 35 | 36 | ||
| 36 | private String tipoFonteSelecionada; |
37 | private String tipoFonteSelecionada; |
| - | 38 | private Integer contadorCandleParaVerificar; |
|
| - | 39 | private List<String> logs; |
|
| 37 | 40 | ||
| 38 | private List<PadraoGatilho> padroesEmAberto; |
41 | private List<PadraoGatilho> padroesEmAberto; |
| 39 | private Integer contadorUltimoCandle; |
42 | private Integer contadorUltimoCandle; |
| 40 | 43 | ||
| 41 | private List<PadraoGatilho> padroes; |
44 | private List<PadraoGatilho> padroes; |
| 42 | private List<PadraoGatilho> padroesComG3; // completos (G3 != null) |
45 | private List<PadraoGatilho> padroesComG3; // completos (G3 != null) |
| 43 | private List<PadraoGatilho> padroesAteG2; // parciais (G2 != null && G3 == null) |
46 | private List<PadraoGatilho> padroesAteG2; // parciais (G2 != null && G3 == null) |
| 44 | 47 | ||
| 45 | private List<SinalTradeGatilho3> sinaisTradeGatilho3; |
48 | private List<SinalTradeGatilho3> sinaisTradeGatilho3; |
| 46 | private List<ResultadoEstrategiaGatilho3> resultados; |
49 | private List<ResultadoEstrategiaGatilho3> resultados; |
| - | 50 | ||
| 47 | 51 | ||
| 48 | @Inject |
52 | @Inject |
| 49 | public RoboBean(RoboOperadorService roboOperadorService) { |
53 | public RoboBean(RoboOperadorService roboOperadorService) { |
| 50 | this.roboOperadorService = roboOperadorService; |
54 | this.roboOperadorService = roboOperadorService; |
| 51 | }
|
55 | }
|
| Line 63... | Line 67... | ||
| 63 | setPadroesComG3(new ArrayList<PadraoGatilho>()); |
67 | setPadroesComG3(new ArrayList<PadraoGatilho>()); |
| 64 | setPadroesAteG2(new ArrayList<PadraoGatilho>()); |
68 | setPadroesAteG2(new ArrayList<PadraoGatilho>()); |
| 65 | setSinaisTradeGatilho3(new ArrayList<SinalTradeGatilho3>()); |
69 | setSinaisTradeGatilho3(new ArrayList<SinalTradeGatilho3>()); |
| 66 | setResultados(new ArrayList<ResultadoEstrategiaGatilho3>()); |
70 | setResultados(new ArrayList<ResultadoEstrategiaGatilho3>()); |
| 67 | setTipoFonteSelecionada(TipoFonteDadosProfit.TEMPO_REAL.getValor()); |
71 | setTipoFonteSelecionada(TipoFonteDadosProfit.TEMPO_REAL.getValor()); |
| - | 72 | setContadorCandleParaVerificar(0); |
|
| 68 | }
|
73 | }
|
| 69 | 74 | ||
| 70 | @Override |
75 | @Override |
| 71 | public GenericService<RoboDTO> getService() { |
76 | public GenericService<RoboDTO> getService() { |
| 72 | return roboOperadorService; |
77 | return roboOperadorService; |
| Line 124... | Line 129... | ||
| 124 | this.tipoFonteSelecionada = tipoFonteSelecionada; |
129 | this.tipoFonteSelecionada = tipoFonteSelecionada; |
| 125 | }
|
130 | }
|
| 126 | 131 | ||
| 127 | public TipoFonteDadosProfit[] getTiposFonteDadosProfit() { |
132 | public TipoFonteDadosProfit[] getTiposFonteDadosProfit() { |
| 128 | return TipoFonteDadosProfit.values(); |
133 | return TipoFonteDadosProfit.values(); |
| - | 134 | }
|
|
| - | 135 | ||
| - | 136 | public List<String> getLogs() { |
|
| - | 137 | return logs; |
|
| - | 138 | }
|
|
| - | 139 | public void setLogs(List<String> logs) { |
|
| - | 140 | this.logs = logs; |
|
| - | 141 | }
|
|
| - | 142 | ||
| - | 143 | public String getLogsBacktestAsText() { |
|
| - | 144 | if (logs == null || logs.isEmpty()) return ""; |
|
| - | 145 | return String.join("\n", logs); |
|
| - | 146 | }
|
|
| - | 147 | ||
| - | 148 | public Integer getContadorCandleParaVerificar() { |
|
| - | 149 | return contadorCandleParaVerificar; |
|
| - | 150 | }
|
|
| - | 151 | public void setContadorCandleParaVerificar(Integer contadorCandleParaVerificar) { |
|
| - | 152 | this.contadorCandleParaVerificar = contadorCandleParaVerificar; |
|
| 129 | }
|
153 | }
|
| 130 | 154 | ||
| 131 | public void iniciar() { |
155 | public void iniciar() { |
| 132 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
156 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
| 133 | public void execute() { |
157 | public void execute() { |
| 134 | roboOperadorService.iniciarOperacao(getTipoFonteSelecionada()); |
- | |
| - | 158 | roboOperadorService.iniciarOperacao(getTipoFonteSelecionada(), getContadorCandleParaVerificar()); |
|
| 135 | setEntidade(roboOperadorService.statusRobo()); |
159 | setEntidade(roboOperadorService.statusRobo()); |
| 136 | LancadorMensagem.lancarSucesso("ROBÔ INICIADO COM SUCESSO!"); |
160 | LancadorMensagem.lancarSucesso("ROBÔ INICIADO COM SUCESSO!"); |
| 137 | }
|
161 | }
|
| 138 | }); |
162 | }); |
| 139 | }
|
163 | }
|
| Line 148... | Line 172... | ||
| 148 | }); |
172 | }); |
| 149 | }
|
173 | }
|
| 150 | 174 | ||
| 151 | public void preencherOutrosPadroes() { |
175 | public void preencherOutrosPadroes() { |
| 152 | padroesComG3 = padroes.stream() |
176 | padroesComG3 = padroes.stream() |
| 153 | .filter(p -> p.getGatilho2() != null && p.getGatilho3() != null) |
- | |
| - | 177 | .filter(p -> p.getTipoPadrao() == TipoPadrao.COMPLETO_G3) |
|
| 154 | .collect(Collectors.toList()); |
178 | .collect(Collectors.toList()); |
| 155 | padroesComG3 = inverterLista(padroesComG3); |
179 | padroesComG3 = inverterLista(padroesComG3); |
| 156 | 180 | ||
| 157 | padroesAteG2 = padroes.stream() |
181 | padroesAteG2 = padroes.stream() |
| 158 | .filter(p -> p.getGatilho2() != null && p.getGatilho3() == null) |
- | |
| - | 182 | .filter(p -> p.getTipoPadrao() == TipoPadrao.PARCIAL_G2) |
|
| 159 | .collect(Collectors.toList()); |
183 | .collect(Collectors.toList()); |
| 160 | padroesAteG2 = inverterLista(padroesAteG2); |
184 | padroesAteG2 = inverterLista(padroesAteG2); |
| 161 | }
|
185 | }
|
| 162 | 186 | ||
| 163 | public static List<PadraoGatilho> inverterLista(List<PadraoGatilho> candles) { |
187 | public static List<PadraoGatilho> inverterLista(List<PadraoGatilho> candles) { |
| Line 172... | Line 196... | ||
| 172 | if (getEntidade().getPadroes().size() != getPadroes().size()) { |
196 | if (getEntidade().getPadroes().size() != getPadroes().size()) { |
| 173 | AlertaPadraoService.novoAlerta("NOVO PADRÃO IDENTIFICADO!"); |
197 | AlertaPadraoService.novoAlerta("NOVO PADRÃO IDENTIFICADO!"); |
| 174 | PrimeFaces.current().executeScript("playAlertaAgressivo();"); |
198 | PrimeFaces.current().executeScript("playAlertaAgressivo();"); |
| 175 | }
|
199 | }
|
| 176 | setPadroes(getEntidade().getPadroes()); |
200 | setPadroes(getEntidade().getPadroes()); |
| - | 201 | setLogs(getEntidade().getLogs()); |
|
| 177 | preencherOutrosPadroes(); |
202 | preencherOutrosPadroes(); |
| 178 | setSinaisTradeGatilho3(getEntidade().getSinaisTradeGatilho3()); |
203 | setSinaisTradeGatilho3(getEntidade().getSinaisTradeGatilho3()); |
| 179 | setResultados(getEntidade().getResultados()); |
204 | setResultados(getEntidade().getResultados()); |
| 180 | }
|
205 | }
|
| 181 | verificarNovosPadroes(); |
206 | verificarNovosPadroes(); |
| Line 198... | Line 223... | ||
| 198 | // Toca o som no cliente
|
223 | // Toca o som no cliente
|
| 199 | PrimeFaces.current().executeScript("playBeepPadrao();"); |
224 | PrimeFaces.current().executeScript("playBeepPadrao();"); |
| 200 | // Se estiver em PF antigo:
|
225 | // Se estiver em PF antigo:
|
| 201 | // RequestContext.getCurrentInstance().execute("playBeepPadrao();");
|
226 | // RequestContext.getCurrentInstance().execute("playBeepPadrao();");
|
| 202 | }
|
227 | }
|
| - | 228 | }
|
|
| - | 229 | ||
| - | 230 | public void verificarCandle() { |
|
| - | 231 | ||
| 203 | }
|
232 | }
|
| 204 | 233 | ||
| 205 | }
|
234 | }
|