/// <summary> /// /// </summary> /// <param name="report"></param> public void OrdemAlterada(OrdemInfo report) { // Envia o report para os assinantes logger.Debug("On OrdemAlterada(): recebeu report "); TradutorFix.DumpOrdemInfo(report); lock (_executionsReportsSubscribers) { if (_executionsReportsSubscribers.Count > 0) { _sendExecutionReport(report); } else { _enqueueExecutionReport(report); } } // Reseta o contador do heartbeat lock (_canais) { if (_canais.ContainsKey(report.Exchange + report.ChannelID)) { CanalInfo canal = (CanalInfo)_canais[report.Exchange + report.ChannelID]; canal.Conectado = true; canal.LastHeartbeat = _getSecsFromTicks(DateTime.Now.Ticks); } } }
/// <summary> /// Envia um pedido de execucao de ordem para o canal correspondente /// </summary> /// <param name="request"></param> /// <returns></returns> public ExecutarOrdemResponse ExecutarOrdem(ExecutarOrdemRequest request) { ExecutarOrdemResponse response = new ExecutarOrdemResponse(); CanalInfo _canal = null; StatusRoteamentoEnum status = StatusRoteamentoEnum.Sucesso; string msg = "Ordem Enviada"; logger.Debug("*** ExecutarOrdem()"); TradutorFix.DumpOrdemInfo(request.info); try { _canal = (CanalInfo)_canais[request.info.Exchange + request.info.ChannelID]; if (_canal == null) { msg = "Nao ha canal configurado para " + request.info.Exchange + "-" + request.info.ChannelID; status = StatusRoteamentoEnum.Erro; logger.Info(msg); response.DadosRetorno = RoteadorOrdensUtil.FormatarRespostaEO(msg, status); } else { if (_canal.roteador == null || _canal.Conectado == false) { status = StatusRoteamentoEnum.Erro; msg = "Nao ha canal ativo e conectado para " + request.info.Exchange + "-" + request.info.ChannelID; logger.Info(msg); response.DadosRetorno = RoteadorOrdensUtil.FormatarRespostaEO(msg, status); } else { _criaReportStore(request.info.ClOrdID); _notificaEnvioParaCanal(request.info); response = _canal.roteador.ExecutarOrdem(request); } } } catch (Exception ex) { msg = "Error ExecutarOrdem(): " + ex.Message; status = StatusRoteamentoEnum.Erro; logger.Error(msg + "-" + ex.StackTrace); response.DadosRetorno = RoteadorOrdensUtil.FormatarRespostaEO(msg, status); if (_canal != null) { _resetCanal(_canal); } } logger.Debug("*** End of ExecutarOrdem()"); return(response); }
/// <summary> /// ConsistirOrdem - efetuar consistencia do order info /// </summary> /// <param name="ordem"></param> /// <param name="alteracao">flag para indicar se é ou nao alteracao de ordem</param> public static void ConsistirOrdem(OrdemInfo ordem, bool alteracao = false) { // Basic order identification if (ordem.Account < 0) { throw new ArgumentException("Account field must be provided"); } if (alteracao) { if (ordem.OrigClOrdID == null || ordem.OrigClOrdID.Length <= 0) { throw new ArgumentException("OrigClOrdID field must be provided"); } } if (ordem.ClOrdID == null || ordem.ClOrdID.Length <= 0) { throw new ArgumentException("ClOrdID field must be provided"); } // Instrument Identification Block if (ordem.Symbol == null || ordem.Symbol.Length <= 0) { throw new ArgumentException("Symbol must be provided"); } if (ordem.SecurityID == null || ordem.SecurityID.Length <= 0) { throw new ArgumentException("SecurityID field must be provided"); } if (ordem.OrderQty <= 0) { throw new ArgumentException("OrderQty must be > 0 "); } // Cliente if (ordem.ExecBroker == null || ordem.ExecBroker.Length <= 0) { throw new ArgumentException("ExecBroker must be provided"); } TimeInForce tif = TradutorFix.deOrdemValidadeParaTimeInForce(ordem.TimeInForce); if (tif == null) { throw new ArgumentException("TimeInForce is invalid"); } if (ordem.TimeInForce == OrdemValidadeEnum.ValidoAteDeterminadaData) { if (ordem.ExpireDate == null || ordem.ExpireDate <= DateTime.Now) { throw new ArgumentException("ExpireDate is invalid"); } } OrdType ordType = TradutorFix.deOrdemTipoParaOrdType(ordem.OrdType); if (ordType == null) { throw new ArgumentException("OrdType is invalid"); } // Verifica envio do preco switch (ordem.OrdType) { case OrdemTipoEnum.Limitada: case OrdemTipoEnum.MarketWithLeftOverLimit: if (ordem.Price <= 0.0 && ordem.TimeInForce != OrdemValidadeEnum.BoaParaLeilao) { throw new ArgumentException("Price must be > 0"); } break; case OrdemTipoEnum.StopLimitada: case OrdemTipoEnum.StopStart: if (ordem.Price <= 0.0) { throw new ArgumentException("Price must be > 0"); } if (ordem.StopPrice <= 0.0) { throw new ArgumentException("StopPrice must be > 0"); } break; case OrdemTipoEnum.Mercado: case OrdemTipoEnum.OnClose: break; default: if (ordem.Price <= 0.0) { throw new ArgumentException("Price must be > 0"); } break; } if (ordem.MaxFloor < 0) { throw new ArgumentException("MaxFloor must be >= 0"); } if (ordem.MinQty < 0) { throw new ArgumentException("MinQty must be >= 0"); } if (ordem.ExecBroker == null || ordem.ExecBroker.Length <= 0) { throw new ArgumentException("ExecBroker must be provided"); } }