public bool EnviarOrdemCross(OrdemCrossInfo crossinfo) { OrdemInfo ordemCompra = crossinfo.OrdemInfoCompra; OrdemInfo ordemVenda = crossinfo.OrdemInfoVenda; // Cria mensagem de new order cross - // Essa mensagem nao é padrao do 4.2 - some weird f*****g things can // f*****g happen with this f*****g shit code QuickFix.FIX44.NewOrderCross ordercross = new QuickFix.FIX44.NewOrderCross(); ordercross.Set(new CrossID(crossinfo.CrossID)); // Unico valor aceito 1 - Negocio executado total ou parcial ordercross.Set(new CrossType(1)); // Prioridade de uma das pontas. Unico valor aceito: 0 - nenhuma ordercross.Set(new CrossPrioritization(0)); // Ordem cross, sempre 2 pernas // Informacoes da perna de compra QuickFix.FIX44.NewOrderCross.NoSidesGroup sideGroupC = new QuickFix.FIX44.NewOrderCross.NoSidesGroup(); sideGroupC.Set(new Side(Side.BUY)); sideGroupC.Set(new ClOrdID(ordemCompra.ClOrdID)); if (ordemCompra.Account > 0) { sideGroupC.Set(new Account(ordemCompra.Account.ToString())); } sideGroupC.Set(new OrderQty(ordemCompra.OrderQty)); //sideGroupC.Set(new PositionEffect('C')); if (ordemCompra.PositionEffect != null && ordemCompra.PositionEffect.Equals("C")) { sideGroupC.Set(new PositionEffect('C')); } // PartIDs Compra // Cliente QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroupC1 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroupC1.Set(new PartyID(ordemCompra.ExecBroker)); PartyIDGroupC1.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroupC1.Set(new PartyRole(PartyRole.ENTERING_TRADER)); // Corretora QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroupC2 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroupC2.Set(new PartyID("227")); PartyIDGroupC2.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroupC2.Set(new PartyRole(PartyRole.ENTERING_FIRM)); // Sender Location QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroupC3 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroupC3.Set(new PartyID("GRA")); PartyIDGroupC3.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroupC3.Set(new PartyRole(54)); // Adiciono os partIDs ao Side (perna de Compra) sideGroupC.AddGroup(PartyIDGroupC1); sideGroupC.AddGroup(PartyIDGroupC2); sideGroupC.AddGroup(PartyIDGroupC3); //BEI - 2012-Nov-14 if (ordemCompra.ForeignFirm != null && ordemCompra.ForeignFirm.Length > 0) { QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroupC4 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroupC4.Set(new PartyID(ordemCompra.ForeignFirm)); PartyIDGroupC4.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroupC4.Set(new PartyRole(PartyRole.FOREIGN_FIRM)); sideGroupC.AddGroup(PartyIDGroupC4); } //SelfTradeProtection - 2012-Nov-27 if (ordemCompra.InvestorID != null && ordemCompra.InvestorID.Length > 0) { QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup4 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup4.Set(new PartyID(ordemCompra.InvestorID)); PartyIDGroup4.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup4.Set(new PartyRole(PartyRole.INVESTOR_ID)); sideGroupC.AddGroup(PartyIDGroup4); } if (ordemCompra.Account > 0) { QuickFix.FIX44.NewOrderSingle.NoAllocsGroup noAllocsGrpC = new QuickFix.FIX44.NewOrderSingle.NoAllocsGroup(); noAllocsGrpC.Set(new AllocAccount(ordemCompra.Account.ToString())); noAllocsGrpC.Set(new AllocAcctIDSource(99)); sideGroupC.AddGroup(noAllocsGrpC); } // Insere informacoes da perna de venda QuickFix.FIX44.NewOrderCross.NoSidesGroup sideGroupV = new QuickFix.FIX44.NewOrderCross.NoSidesGroup(); sideGroupV.Set(new Side(Side.SELL)); sideGroupV.Set(new ClOrdID(ordemVenda.ClOrdID)); if (ordemVenda.Account > 0) { sideGroupV.Set(new Account(ordemVenda.Account.ToString())); } sideGroupV.Set(new OrderQty(ordemVenda.OrderQty));; sideGroupV.Set(new PositionEffect('C')); if (ordemVenda.PositionEffect != null && ordemVenda.PositionEffect.Equals("C")) { sideGroupV.Set(new PositionEffect('C')); } // Cliente QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup1 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup1.Set(new PartyID(ordemVenda.ExecBroker)); PartyIDGroup1.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup1.Set(new PartyRole(PartyRole.ENTERING_TRADER)); // Corretora QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup2 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup2.Set(new PartyID("227")); PartyIDGroup2.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup2.Set(new PartyRole(PartyRole.ENTERING_FIRM)); // Sender Location ID QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup3 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup3.Set(new PartyID("GRA")); PartyIDGroup3.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup3.Set(new PartyRole(54)); // Adiciono os partIDs ao Side (perna de venda) sideGroupV.AddGroup(PartyIDGroup1); sideGroupV.AddGroup(PartyIDGroup2); sideGroupV.AddGroup(PartyIDGroup3); //BEI - 2012-Nov-14 if (ordemVenda.ForeignFirm != null && ordemVenda.ForeignFirm.Length > 0) { QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroupV4 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroupV4.Set(new PartyID(ordemVenda.ForeignFirm)); PartyIDGroupV4.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroupV4.Set(new PartyRole(PartyRole.FOREIGN_FIRM)); sideGroupV.AddGroup(PartyIDGroupV4); } //SelfTradeProtection - 2012-Nov-27 if (ordemVenda.InvestorID != null && ordemVenda.InvestorID.Length > 0) { QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup4 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup4.Set(new PartyID(ordemVenda.InvestorID)); PartyIDGroup4.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup4.Set(new PartyRole(PartyRole.INVESTOR_ID)); sideGroupV.AddGroup(PartyIDGroup4); } if (ordemVenda.Account > 0) { QuickFix.FIX44.NewOrderSingle.NoAllocsGroup noAllocsGrpV = new QuickFix.FIX44.NewOrderSingle.NoAllocsGroup(); noAllocsGrpV.Set(new AllocAccount(ordemVenda.Account.ToString())); noAllocsGrpV.Set(new AllocAcctIDSource(99)); sideGroupV.AddGroup(noAllocsGrpV); } // Insere os grupos das 2 pernas ordercross.AddGroup(sideGroupC); ordercross.AddGroup(sideGroupV); ordercross.Set(new Symbol(crossinfo.Symbol)); if (crossinfo.SecurityID != null && crossinfo.SecurityID.Length > 0) { ordercross.Set(new SecurityID(crossinfo.SecurityID)); ordercross.Set(new SecurityIDSource("8")); } OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(crossinfo.OrdType); if (ordType != null) { ordercross.Set(ordType); } ordercross.Set(new Price(Convert.ToDecimal(crossinfo.Price))); ordercross.Set(new TransactTime(DateTime.Now)); // Memo Field if (crossinfo.Memo5149 != null && crossinfo.Memo5149.Length > 0) { if (crossinfo.Memo5149.Length > 50) { crossinfo.Memo5149 = crossinfo.Memo5149.Substring(0, 50); } StringField memo5149 = new StringField(5149, crossinfo.Memo5149); ordercross.SetField(memo5149); } bool bRet = Session.SendToTarget(ordercross, _session.SessionID); return(bRet); }
public bool EnviarOrdemCross(OrdemCrossInfo crossinfo) { throw new NotImplementedException("EnviarOrdemCross"); }
private void btOrderX_Click(object sender, EventArgs e) { try { frmPontaVenda frm = new frmPontaVenda(); OrdemInfo ordemCompra = new OrdemInfo(); ordemCompra.ClOrdID = txtClOrdID.Text; ordemCompra.Account = Convert.ToInt32(txtCodCliente.Text); ordemCompra.ChannelID = Convert.ToInt32(txtOperador.Text); if (cmbBolsa.SelectedItem.Equals("BOVESPA")) { ordemCompra.Exchange = "BOVESPA"; } else { ordemCompra.Exchange = "BMF"; } ordemCompra.ExchangeNumberID = txtExchangeNumber.Text; ordemCompra.Price = Convert.ToDouble(txtPreco.Text); ordemCompra.OrderQty = Convert.ToInt32(txtQtde.Text); ordemCompra.MinQty = Convert.ToInt32(txtQtdeMin.Text); ordemCompra.MaxFloor = Convert.ToInt32(txtQtdeAparente.Text); ordemCompra.Symbol = txtPapel.Text; ordemCompra.SecurityID = txtSecurityId.Text; ordemCompra.RegisterTime = DateTime.Now; ordemCompra.TransactTime = DateTime.Now; ordemCompra.ExecBroker = txtTraderID.Text; if (rdCompra.Checked) { ordemCompra.Side = OrdemDirecaoEnum.Compra; } else { ordemCompra.Side = OrdemDirecaoEnum.Venda; } if (txtStopPX.Text.Length > 0 && Convert.ToDouble(txtStopPX.Text) > 0) { ordemCompra.StopPrice = Convert.ToDouble(txtStopPX.Text); } if (txtInvestorID.Text.Length > 0) { ordemCompra.InvestorID = txtInvestorID.Text; } switch (cmbOrderType.SelectedIndex) { case 0: ordemCompra.OrdType = OrdemTipoEnum.Limitada; break; case 1: ordemCompra.OrdType = OrdemTipoEnum.StopLimitada; break; case 2: ordemCompra.OrdType = OrdemTipoEnum.MarketWithLeftOverLimit; break; case 3: ordemCompra.OrdType = OrdemTipoEnum.OnClose; break; case 4: ordemCompra.OrdType = OrdemTipoEnum.StopStart; break; case 5: ordemCompra.OrdType = OrdemTipoEnum.Mercado; break; case 6: ordemCompra.OrdType = OrdemTipoEnum.StopLoss; break; default: ordemCompra.OrdType = OrdemTipoEnum.OnClose; break; } switch (cmbTipoValidade.SelectedIndex) { case 0: ordemCompra.TimeInForce = OrdemValidadeEnum.ValidaParaODia; ordemCompra.ExpireDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); break; case 1: ordemCompra.TimeInForce = OrdemValidadeEnum.ExecutaIntegralParcialOuCancela; break; case 2: ordemCompra.TimeInForce = OrdemValidadeEnum.ExecutaIntegralOuCancela; break; case 3: ordemCompra.TimeInForce = OrdemValidadeEnum.ValidaAteSerCancelada; break; case 4: ordemCompra.TimeInForce = OrdemValidadeEnum.ValidoAteDeterminadaData; ordemCompra.ExpireDate = DateTime.ParseExact(txtDataValidade.Text + " 23:59:59", "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture); break; default: ordemCompra.TimeInForce = OrdemValidadeEnum.ValidaParaAberturaDoMercado; break; } lastCLOrdID++; frm.ClOrdID = lastCLOrdID.ToString(); frm.Qtde = txtQtde.Text; DialogResult result = frm.ShowDialog(); if (result == DialogResult.OK) { OrdemInfo ordemVenda = RoteadorOrdensUtil.CloneOrder(ordemCompra); ordemVenda.Account = Convert.ToInt32(frm.Account); ordemVenda.OrderQty = Convert.ToInt32(frm.Qtde); ordemVenda.ClOrdID = frm.ClOrdID; if (frm.InvestorID.Length > 0) { ordemVenda.InvestorID = frm.ClOrdID; } OrdemCrossInfo cross = new OrdemCrossInfo(); cross.ChannelID = ordemCompra.ChannelID; cross.CrossID = ordemCompra.ClOrdID + "X"; cross.Exchange = ordemCompra.Exchange; cross.OrdType = ordemCompra.OrdType; cross.Price = ordemCompra.Price; cross.SecurityID = ordemCompra.SecurityID; cross.SecurityIDSource = ordemCompra.SecurityIDSource; cross.Symbol = ordemCompra.Symbol; cross.TransactTime = ordemCompra.RegisterTime; cross.OrdemInfoCompra = ordemCompra; cross.OrdemInfoVenda = ordemVenda; cross.Memo5149 = "Cross " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.fff"); IRoteadorOrdens roteador = Ativador.Get <IRoteadorOrdens>(); if (roteador != null) { ExecutarOrdemCrossRequest request = new ExecutarOrdemCrossRequest(); request.info = cross; ExecutarOrdemCrossResponse resp = roteador.ExecutarOrdemCross(request); if (resp.DadosRetorno != null) { string msg = ""; foreach (OcorrenciaRoteamentoOrdem ocorr in resp.DadosRetorno.Ocorrencias) { msg += ocorr.Ocorrencia + "\r\n"; } if (resp.DadosRetorno.StatusResposta == StatusRoteamentoEnum.Erro) { MessageBox.Show(msg); } else { _addMsg(msg); lock (ofertasenviadas) { ofertasenviadas.Add(ordemCompra); SerializadorOfertas.SaveOfertas(ofertasenviadas); } } } } } } catch (Exception ex) { _addMsg(ex.Message); logger.Error("Erro: " + ex.Message, ex); } lastCLOrdID++; txtClOrdID.Text = lastCLOrdID.ToString(); }