public void OnMessage(QuickFix.FIX42.ExecutionReport m, SessionID s) { _mainform._addMsg("Received execution report (4.2)\r\n"); string msg = "Order Dump Begin =======================\r\n"; msg += "\r\n"; msg += "OrdemInfo:\r\n"; msg += "==========\r\n"; msg += "Account .........: " + m.Account.getValue() + "\r\n"; msg += "Numero da ordem .: " + m.ClOrdID.getValue() + "\r\n"; msg += "Symbol ..........: " + m.Symbol.getValue() + "\r\n"; msg += "ExchangeNumber ..: " + m.OrderID.getValue() + "\r\n"; msg += "Status ..........: " + m.OrdStatus.getValue() + "\r\n"; msg += "Status ..........: " + FixMessageUtilities.TraduzirOrdemStatus(m.OrdStatus.getValue()) + "\r\n"; msg += "Quantidade ......: " + m.OrderQty.getValue() + "\r\n"; msg += "Qtde restante ...: " + (m.OrderQty.getValue() - m.CumQty.getValue()) + "\r\n"; if (m.IsSetLastPx()) { msg += "Preco ...........: " + m.LastPx.getValue() + "\r\n"; } if (m.IsSetText()) { msg += "Text ............: [" + m.Text.getValue() + "]\r\n"; } if (m.IsSetField(5149)) { msg += "Memo5149 ........: " + m.GetString(5149) + "\r\n"; } msg += "\r\n"; msg += "\r\nOrder Dump End =========================\r\n"; _mainform._addMsg(msg); }
public bool AlterarOrdem(OrdemInfo ordem, long ini = 0, long fim = 0, long oriini = 0, long orifim = 0, int delay = 0, string mnemonic = "", string senderSubID = "", string extraTags = "") { //Cria a mensagem FIX de NewOrderSingle QuickFix.FIX42.OrderCancelReplaceRequest ordercrr = new QuickFix.FIX42.OrderCancelReplaceRequest(); ordercrr.Set(new Account(ordem.Account.ToString())); if (!string.IsNullOrEmpty(mnemonic)) { ordercrr.SetField(new Account(mnemonic), true); } if (!string.IsNullOrEmpty(senderSubID)) { ordercrr.Header.SetField(new SenderSubID(senderSubID), true); } ordercrr.Set(new Symbol(ordem.Symbol)); ordercrr.Set(new ClOrdID(ordem.ClOrdID)); ordercrr.Set(new OrigClOrdID(ordem.OrigClOrdID)); if (ordem.ExchangeNumberID != null && ordem.ExchangeNumberID.Length > 0) { ordercrr.Set(new OrderID(ordem.ExchangeNumberID)); } // Armazena ClOrdID em Memo (5149) para posterior referência nos tratamentos de retornos QuickFix.Fields.StringField field5149 = new QuickFix.Fields.StringField(5149, ordem.ClOrdID); ordercrr.SetField(field5149); //ordersingle.Set(new IDSource()); if (ordem.Side == OrdemDirecaoEnum.Venda) { ordercrr.Set(new Side(Side.SELL)); } else { ordercrr.Set(new Side(Side.BUY)); } TimeInForce tif = FixMessageUtilities.deOrdemValidadeParaTimeInForce(ordem.TimeInForce); if (tif != null) { ordercrr.Set(tif); } ordercrr.Set(new OrderQty(ordem.OrderQty)); if (ordem.TimeInForce == OrdemValidadeEnum.ValidoAteDeterminadaData) { DateTime expiredate = Convert.ToDateTime(ordem.ExpireDate); ordercrr.Set(new ExpireDate(expiredate.ToString("yyyyMMdd"))); } OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(ordem.OrdType); if (ordType != null) { ordercrr.Set(ordType); } // Para versao 4.2, os novos tipos de OrdType a serem enviados (5, A ou B); if (!string.IsNullOrEmpty(ordem.Memo5149)) { ordercrr.SetField(new OrdType(Convert.ToChar(ordem.Memo5149)), true); } // Verifica envio do preco switch (ordem.OrdType) { case OrdemTipoEnum.Limitada: case OrdemTipoEnum.MarketWithLeftOverLimit: case OrdemTipoEnum.StopLimitada: ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price))); break; case OrdemTipoEnum.StopStart: ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price))); ordercrr.Set(new StopPx(Convert.ToDecimal(ordem.StopPrice))); break; case OrdemTipoEnum.Mercado: case OrdemTipoEnum.OnClose: ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price))); break; default: ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price))); break; } ordercrr.Set(new TransactTime(DateTime.Now)); ordercrr.Set(new HandlInst('1')); ordercrr.Set(new ExecBroker("227")); if (ordem.MaxFloor > 0) { ordercrr.Set(new MaxFloor(Convert.ToDecimal(ordem.MaxFloor))); } if (ordem.MinQty > 0) { ordercrr.Set(new MinQty(Convert.ToDecimal(ordem.MinQty))); } QuickFix.FIX42.OrderCancelReplaceRequest.NoAllocsGroup noAllocsGrp = new QuickFix.FIX42.OrderCancelReplaceRequest.NoAllocsGroup(); noAllocsGrp.Set(new AllocAccount("67")); ordercrr.AddGroup(noAllocsGrp); bool bRet = false; // Tags Customizadas Bloomberg if (!string.IsNullOrEmpty(extraTags)) { string[] arr = extraTags.Split(';'); for (int i = 0; i < arr.Length; i++) { if (!string.IsNullOrEmpty(arr[i])) { string[] valor = arr[i].Split('='); StringField fld = new StringField(Convert.ToInt32(valor[0]), valor[1]); ordercrr.SetField(fld); } } } if (oriini != 0 && orifim != 0) { long times = fim - ini; logger.Info("=====================================> INICIO ALTERAR ORDEM========> Qtd: " + times); for (long i = 0; i < times; i++) { ClOrdID xx = new ClOrdID(ini.ToString()); OrigClOrdID xx2 = new OrigClOrdID(oriini.ToString()); ordercrr.ClOrdID = xx; ordercrr.OrigClOrdID = xx2; bRet = Session.SendToTarget(ordercrr, _session.SessionID); if (!bRet) { logger.Info("erro"); break; } if (0 != delay) { Thread.Sleep(delay); } ini++; oriini++; } logger.Info("=====================================> FIM ALTERAR ORDEM========> Qtd: " + times); } else { bRet = Session.SendToTarget(ordercrr, _session.SessionID); } return(bRet); }
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 void ExecOrders(object arg) * { * NewOrderSingle ordem = (NewOrderSingle)arg; * long clordid = Convert.ToInt64(DateTime.Now.ToString("yyyyMMddhhmmssfff")); * bool bRet; * logger.Info("=====================================> INICIO ========> Regs: " + _times); * for (int i =0; i<_times; i++) * { * ClOrdID xx = new ClOrdID(clordid++.ToString()); * ordem.ClOrdID = xx; * //Thread.Sleep(1); * bRet = Session.SendToTarget(ordem, _session.SessionID); * } * logger.Info("=====================================> FIM ========> Regs: " + _times); * } */ public bool AlterarOrdem(OrdemInfo ordem, long ini = 0, long fim = 0, long oriini = 0, long orifim = 0, int delay = 0, string mnemonic = "") { //Cria a mensagem FIX de NewOrderSingle QuickFix.FIX44.OrderCancelReplaceRequest orderCancelReplaceReq = new QuickFix.FIX44.OrderCancelReplaceRequest(); orderCancelReplaceReq.Set(new OrigClOrdID(ordem.OrigClOrdID)); if (ordem.Account > 0) { orderCancelReplaceReq.Set(new Account(ordem.Account.ToString())); } if (!string.IsNullOrEmpty(mnemonic)) { orderCancelReplaceReq.SetField(new Account(mnemonic), true); } // Instrument Identification Block orderCancelReplaceReq.Set(new Symbol(ordem.Symbol)); orderCancelReplaceReq.Set(new SecurityID(ordem.SecurityID)); orderCancelReplaceReq.Set(new SecurityIDSource(SecurityIDSource.EXCHANGE_SYMBOL)); if (ordem.ExchangeNumberID != null && ordem.ExchangeNumberID.Length > 0) { orderCancelReplaceReq.Set(new OrderID(ordem.ExchangeNumberID)); } orderCancelReplaceReq.Set(new ClOrdID(ordem.ClOrdID)); //ordersingle.set(new IDSource()); if (ordem.Side == OrdemDirecaoEnum.Venda) { orderCancelReplaceReq.Set(new Side(Side.SELL)); } else { orderCancelReplaceReq.Set(new Side(Side.BUY)); } orderCancelReplaceReq.Set(new Price(Convert.ToDecimal(ordem.Price))); TimeInForce tif = FixMessageUtilities.deOrdemValidadeParaTimeInForce(ordem.TimeInForce); if (tif != null) { orderCancelReplaceReq.Set(tif); } orderCancelReplaceReq.Set(new OrderQty(ordem.OrderQty)); if (ordem.TimeInForce == OrdemValidadeEnum.ValidoAteDeterminadaData) { DateTime expiredate = Convert.ToDateTime(ordem.ExpireDate); orderCancelReplaceReq.Set(new ExpireDate(expiredate.ToString("yyyyMMdd"))); } OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(ordem.OrdType); if (ordType != null) { orderCancelReplaceReq.Set(ordType); } //if (ordem.OrdType == OrdemTipoEnum.StopLimitada ) //{ // ordersingle.set(new StopPx(ordem.StopPx)); //} orderCancelReplaceReq.Set(new TransactTime(DateTime.Now)); // Cliente QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup1 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); PartyIDGroup1.Set(new PartyID(ordem.ExecBroker)); PartyIDGroup1.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup1.Set(new PartyRole(PartyRole.ENTERING_TRADER)); // Corretora QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup2 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); PartyIDGroup2.Set(new PartyID("227")); PartyIDGroup2.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup2.Set(new PartyRole(PartyRole.ENTERING_FIRM)); // Location ID QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup3 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); if (ordem.SenderLocation != null && ordem.SenderLocation.Length > 0) { PartyIDGroup3.Set(new PartyID(ordem.SenderLocation)); } else { PartyIDGroup3.Set(new PartyID("GRA")); } PartyIDGroup3.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup3.Set(new PartyRole(54)); orderCancelReplaceReq.AddGroup(PartyIDGroup1); orderCancelReplaceReq.AddGroup(PartyIDGroup2); orderCancelReplaceReq.AddGroup(PartyIDGroup3); //BEI - 2012-Nov-14 if (ordem.ForeignFirm != null && ordem.ForeignFirm.Length > 0) { QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup4 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); PartyIDGroup4.Set(new PartyID(ordem.ForeignFirm)); PartyIDGroup4.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup4.Set(new PartyRole(PartyRole.FOREIGN_FIRM)); orderCancelReplaceReq.AddGroup(PartyIDGroup4); } if (ordem.Account > 0) { QuickFix.FIX44.OrderCancelReplaceRequest.NoAllocsGroup noAllocsGrp = new QuickFix.FIX44.OrderCancelReplaceRequest.NoAllocsGroup(); noAllocsGrp.Set(new AllocAccount(ordem.Account.ToString())); noAllocsGrp.Set(new AllocAcctIDSource(99)); orderCancelReplaceReq.AddGroup(noAllocsGrp); } //SelfTradeProtection - 2012-Nov-27 if (ordem.InvestorID != null && ordem.InvestorID.Length > 0) { QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup5 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); PartyIDGroup5.Set(new PartyID(ordem.InvestorID)); PartyIDGroup5.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup5.Set(new PartyRole(PartyRole.INVESTOR_ID)); orderCancelReplaceReq.AddGroup(PartyIDGroup5); } if (ordem.ExecutingTrader != null && ordem.ExecutingTrader.Length > 0) { QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup7 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); PartyIDGroup7.Set(new PartyID(ordem.ExecutingTrader)); PartyIDGroup7.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup7.Set(new PartyRole(PartyRole.EXECUTING_TRADER)); orderCancelReplaceReq.AddGroup(PartyIDGroup7); } // Memo Field if (ordem.Memo5149 != null && ordem.Memo5149.Length > 0) { if (ordem.Memo5149.Length > 50) { ordem.Memo5149 = ordem.Memo5149.Substring(0, 50); } StringField memo5149 = new StringField(5149, ordem.Memo5149); orderCancelReplaceReq.SetField(memo5149); } bool bRet = false; if (oriini != 0 && orifim != 0) { long times = fim - ini; logger.Info("=====================================> INICIO ALTERAR ORDEM========> Qtd: " + times); for (long i = 0; i < times; i++) { ClOrdID xx = new ClOrdID(ini.ToString()); OrigClOrdID xx2 = new OrigClOrdID(oriini.ToString()); orderCancelReplaceReq.ClOrdID = xx; orderCancelReplaceReq.OrigClOrdID = xx2; bRet = Session.SendToTarget(orderCancelReplaceReq, _session.SessionID); if (!bRet) { logger.Info("erro"); break; } if (0 != delay) { Thread.Sleep(delay); } ini++; oriini++; //System.Windows.Forms.Application.DoEvents(); } logger.Info("=====================================> FIM ALTERAR ORDEM========> Qtd: " + times); } else { bRet = Session.SendToTarget(orderCancelReplaceReq, _session.SessionID); } return(bRet); }
public bool EnviarOrdem(OrdemInfo ordem, long ini = 0, long fim = 0, int delay = 0, string mnemonic = "") { //Cria a mensagem FIX de NewOrderSingle QuickFix.FIX44.NewOrderSingle ordersingle = new QuickFix.FIX44.NewOrderSingle(); if (ordem.Account > 0) { ordersingle.Set(new Account(ordem.Account.ToString())); } if (!string.IsNullOrEmpty(mnemonic)) { ordersingle.SetField(new Account(mnemonic), true); } // Instrument Identification Block ordersingle.Set(new Symbol(ordem.Symbol)); if (!string.IsNullOrEmpty(ordem.SecurityID)) { ordersingle.Set(new SecurityID(ordem.SecurityID)); } ordersingle.Set(new SecurityIDSource(SecurityIDSource.EXCHANGE_SYMBOL)); //long clOrd =0; ordersingle.Set(new ClOrdID(ordem.ClOrdID)); if (ordem.Side == OrdemDirecaoEnum.Venda) { ordersingle.Set(new Side(Side.SELL)); } else { ordersingle.Set(new Side(Side.BUY)); } TimeInForce tif = FixMessageUtilities.deOrdemValidadeParaTimeInForce(ordem.TimeInForce); if (tif != null) { ordersingle.Set(tif); } ordersingle.Set(new OrderQty(ordem.OrderQty)); if (ordem.TimeInForce == OrdemValidadeEnum.ValidoAteDeterminadaData) { DateTime expiredate = Convert.ToDateTime(ordem.ExpireDate); ordersingle.Set(new ExpireDate(expiredate.ToString("yyyyMMdd"))); } OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(ordem.OrdType); if (ordType != null) { ordersingle.Set(ordType); } // Verifica envio do preco switch (ordem.OrdType) { case OrdemTipoEnum.Limitada: case OrdemTipoEnum.MarketWithLeftOverLimit: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); break; case OrdemTipoEnum.StopLimitada: case OrdemTipoEnum.StopStart: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); ordersingle.Set(new StopPx(Convert.ToDecimal(ordem.StopPrice))); break; case OrdemTipoEnum.Mercado: case OrdemTipoEnum.OnClose: break; default: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); break; } ordersingle.Set(new TransactTime(DateTime.Now)); ordersingle.Set(new HandlInst('1')); if (ordem.MaxFloor > 0) { ordersingle.Set(new MaxFloor(Convert.ToDecimal(ordem.MaxFloor))); } if (ordem.MinQty > 0) { ordersingle.Set(new MinQty(Convert.ToDecimal(ordem.MinQty))); } // Cliente QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup1 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); //PartyIDGroup1.set(new PartyID(ordem.Account.ToString())); PartyIDGroup1.Set(new PartyID(ordem.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)); // Location ID QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup3 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); if (ordem.SenderLocation != null && ordem.SenderLocation.Length > 0) { PartyIDGroup3.Set(new PartyID(ordem.SenderLocation)); } else { PartyIDGroup3.Set(new PartyID("GRA")); } PartyIDGroup3.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup3.Set(new PartyRole(PartyRole.SENDER_LOCATION)); // Corretora QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup4 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup4.Set(new PartyID("245427")); PartyIDGroup4.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup4.Set(new PartyRole(PartyRole.ENTERING_FIRM)); ordersingle.AddGroup(PartyIDGroup1); ordersingle.AddGroup(PartyIDGroup2); ordersingle.AddGroup(PartyIDGroup3); //ordersingle.AddGroup(PartyIDGroup4); //BEI - 2012-Nov-13 if (ordem.ForeignFirm != null && ordem.ForeignFirm.Length > 0) { QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup5 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup5.Set(new PartyID(ordem.ForeignFirm)); PartyIDGroup5.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup5.Set(new PartyRole(PartyRole.FOREIGN_FIRM)); ordersingle.AddGroup(PartyIDGroup5); } //SelfTradeProtection - 2012-Nov-27 if (ordem.InvestorID != null && ordem.InvestorID.Length > 0) { QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup6 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup6.Set(new PartyID(ordem.InvestorID)); PartyIDGroup6.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup6.Set(new PartyRole(PartyRole.INVESTOR_ID)); ordersingle.AddGroup(PartyIDGroup6); } if (ordem.ExecutingTrader != null && ordem.ExecutingTrader.Length > 0) { QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup7 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup7.Set(new PartyID(ordem.ExecutingTrader)); PartyIDGroup7.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup7.Set(new PartyRole(PartyRole.EXECUTING_TRADER)); ordersingle.AddGroup(PartyIDGroup7); } //if (ordem.Account > 0) //{ // QuickFix.FIX44.NewOrderSingle.NoAllocsGroup noAllocsGrp = new QuickFix.FIX44.NewOrderSingle.NoAllocsGroup(); // noAllocsGrp.Set(new AllocAccount(ordem.Account.ToString())); // noAllocsGrp.Set(new AllocAcctIDSource(99)); // ordersingle.AddGroup(noAllocsGrp); //} if (ordem.PositionEffect != null && ordem.PositionEffect.Equals("C")) { ordersingle.Set(new PositionEffect('C')); } // Memo Field if (ordem.Memo5149 != null && ordem.Memo5149.Length > 0) { if (ordem.Memo5149.Length > 50) { ordem.Memo5149 = ordem.Memo5149.Substring(0, 50); } StringField memo5149 = new StringField(5149, ordem.Memo5149); ordersingle.SetField(memo5149); } // AccountType if (ordem.AcountType == ContaTipoEnum.REMOVE_ACCOUNT_INFORMATION) { IntField int581 = new IntField(581, 38); ordersingle.SetField(int581); } else if (ordem.AcountType == ContaTipoEnum.GIVE_UP_LINK_IDENTIFIER) { IntField int581 = new IntField(581, 40); ordersingle.SetField(int581); } bool bRet = false; if (ini == 0) { bRet = Session.SendToTarget(ordersingle, _session.SessionID); } else { //_times = times; //Thread th = new Thread(new ParameterizedThreadStart(ExecOrders)); //th.Start(ordersingle); long times = fim - ini; logger.Info("=====================================> INICIO ========> Qtd: " + times); for (long i = 0; i < times; i++) { //logger.Info("XXX: " + i); ClOrdID xx = new ClOrdID(ini.ToString()); ordersingle.ClOrdID = xx; bRet = Session.SendToTarget(ordersingle, _session.SessionID); if (!bRet) { logger.Info("erro"); break; } if (0 != delay) { Thread.Sleep(delay); } ini++; //System.Windows.Forms.Application.DoEvents(); } logger.Info("=====================================> FIM ========> Qtd: " + times); } return(bRet); }
public static OrdemInfo Fix44ExecutionReport2OrdemInfo(QuickFix.FIX44.ExecutionReport er, FixSessionItem cfg) { try { OrdemInfo order = new OrdemInfo(); string descricao = string.Empty; // order = new OrdemInfo(); order.Account = Convert.ToInt32(er.IsSetAccount() ? er.Account.getValue() : "0"); order.Exchange = cfg.Bolsa; order.ChannelID = cfg.Operador; order.ClOrdID = er.ClOrdID.ToString();//chaveClOrdId; order.OrigClOrdID = er.IsSetOrigClOrdID() ? er.OrigClOrdID.getValue() : null; order.ExecBroker = "227"; if (er.IsSetExpireDate()) { string expdate = er.ExpireDate.getValue() + "235959"; order.ExpireDate = DateTime.ParseExact(expdate, "yyyyMMddHHmmss", CultureInfo.InvariantCulture); } else { order.ExpireDate = DateTime.MinValue; } order.MaxFloor = er.IsSetMaxFloor() ? Convert.ToDouble(er.MaxFloor.getValue()) : 0; order.MinQty = er.IsSetMinQty() ? Convert.ToDouble(er.MinQty.getValue()) : 0; order.OrderQty = Convert.ToInt32(er.IsSetOrderQty() ? er.OrderQty.getValue() : 0); order.OrdType = FixMessageUtilities.TraduzirOrdemTipo(er.OrdType.getValue()); order.Price = er.IsSetPrice() ? Convert.ToDouble(er.Price.getValue()) : 0; order.SecurityID = er.IsSetSecurityID() ? er.SecurityID.ToString() : null; order.Side = er.IsSetSide() ? (OrdemDirecaoEnum)Convert.ToInt32(er.Side.ToString()) : OrdemDirecaoEnum.NaoInformado; order.Symbol = er.IsSetSymbol() ? er.Symbol.ToString() : null; order.TimeInForce = er.IsSetTimeInForce() ? FixMessageUtilities.deTimeInForceParaOrdemValidade(er.TimeInForce) : OrdemValidadeEnum.NaoInformado; //} order.ExchangeNumberID = er.IsSetOrderID() ? er.OrderID.getValue() : null; order.OrderQtyRemmaining = Convert.ToInt32(er.IsSetLeavesQty() ? er.LeavesQty.getValue() : 0); order.CumQty = Convert.ToInt32(er.IsSetCumQty() ? er.CumQty.getValue() : 0); order.OrdStatus = FixMessageUtilities.TraduzirOrdemStatus(er.OrdStatus.getValue()); order.Memo5149 = er.IsSetField(5149) ? er.GetField(5149) : String.Empty; order.PossDupFlag = er.Header.IsSetField(Tags.PossDupFlag) ? er.Header.GetBoolean(Tags.PossDupFlag) : false; order.PossResend = er.Header.IsSetField(Tags.PossResend) ? er.Header.GetBoolean(Tags.PossResend) : false; order.CompIDBolsa = er.Header.IsSetField(Tags.SenderCompID) ? er.Header.GetString(Tags.SenderCompID) : cfg.SenderCompID; order.CompIDOMS = er.Header.IsSetField(Tags.TargetCompID) ? er.Header.GetString(Tags.TargetCompID) : cfg.TargetCompID; switch (order.OrdStatus) { case OrdemStatusEnum.NOVA: descricao = "Ordem aberta"; order.RegisterTime = DateTime.Now; break; case OrdemStatusEnum.CANCELADA: descricao = "Ordem cancelada"; break; case OrdemStatusEnum.PARCIALMENTEEXECUTADA: descricao = "Ordem com execucao parcial"; break; case OrdemStatusEnum.SUSPENSA: descricao = "Ordem suspensa"; break; case OrdemStatusEnum.EXECUTADA: descricao = "Ordem executada"; break; case OrdemStatusEnum.SUBSTITUIDA: descricao = "Ordem substituida"; break; case OrdemStatusEnum.REJEITADA: if (er.IsSetText()) { descricao = er.Text.getValue(); } break; } order.TransactTime = DateTime.Now; // Try get the msg seq number order.FixMsgSeqNum = er.Header.IsSetField(Tags.MsgSeqNum) ? er.Header.GetInt(Tags.MsgSeqNum) : 0; order.ProtectionPrice = Convert.ToDecimal(er.IsSetField(35001) ? er.GetString(35001) : "0"); // Setando informações de acompanhamento AcompanhamentoOrdemInfo acompanhamento = new AcompanhamentoOrdemInfo(); acompanhamento.NumeroControleOrdem = order.ClOrdID; acompanhamento.CodigoDoCliente = order.Account; acompanhamento.CodigoResposta = order.ExchangeNumberID; acompanhamento.CodigoTransacao = er.IsSetExecID() ? er.ExecID.getValue() : null; acompanhamento.Instrumento = order.Symbol; acompanhamento.SecurityID = order.SecurityID; acompanhamento.CanalNegociacao = order.ChannelID; acompanhamento.Direcao = order.Side; acompanhamento.QuantidadeSolicitada = order.OrderQty; acompanhamento.QuantidadeExecutada = (int)er.CumQty.getValue(); acompanhamento.QuantidadeRemanescente = (int)er.LeavesQty.getValue(); acompanhamento.QuantidadeNegociada = er.IsSetLastQty() ? (int)er.LastQty.getValue() : 0; acompanhamento.Preco = new Decimal(order.Price); acompanhamento.StatusOrdem = FixMessageUtilities.TraduzirOrdemStatus(er.OrdStatus.getValue()); acompanhamento.DataOrdemEnvio = order.TransactTime; acompanhamento.DataAtualizacao = DateTime.Now; acompanhamento.CodigoRejeicao = er.IsSetOrdRejReason() ? er.OrdRejReason.ToString() : "0"; acompanhamento.Descricao = descricao; // Try get the msg seq number acompanhamento.FixMsgSeqNum = er.Header.IsSetField(Tags.MsgSeqNum) ? er.Header.GetInt(Tags.MsgSeqNum) : 0; acompanhamento.LastPx = er.IsSetLastPx() ? (Decimal)er.LastPx.getValue() : new Decimal(order.Price); acompanhamento.TradeDate = er.IsSetTradeDate() ? er.TradeDate.getValue() : DateTime.Now.ToString("yyyyMMdd"); //BEI Fields //Added in 2012-Nov-13 by ATP acompanhamento.ExchangeOrderID = er.IsSetField(35022) ? er.GetString(35022) : String.Empty; acompanhamento.ExchangeExecID = er.IsSetField(35023) ? er.GetString(35023) : String.Empty; acompanhamento.LastPxInIssuedCurrency = Convert.ToDecimal(er.IsSetField(35024) ? er.GetString(35024) : "0"); acompanhamento.PriceInIssuedCurrency = Convert.ToDecimal(er.IsSetField(35025) ? er.GetString(35025) : "0"); acompanhamento.ExchangeSecondaryOrderID = er.IsSetField(35026) ? er.GetString(35026) : String.Empty; acompanhamento.TradeLinkID = er.IsSetField(820) ? er.GetString(820) : String.Empty; acompanhamento.OrderLinkID = er.IsSetField(5975) ? er.GetString(5975) : String.Empty; acompanhamento.ExchangeQuoteID = er.IsSetField(5001) ? er.GetString(5001) : String.Empty; acompanhamento.PossDupFlag = er.Header.IsSetField(Tags.PossDupFlag) ? er.Header.GetBoolean(Tags.PossDupFlag) : false; acompanhamento.PossResend = er.Header.IsSetField(Tags.PossResend) ? er.Header.GetBoolean(Tags.PossResend) : false; acompanhamento.CompIDBolsa = er.Header.IsSetField(Tags.SenderCompID) ? er.Header.GetString(Tags.SenderCompID) : cfg.SenderCompID; acompanhamento.CompIDOMS = er.Header.IsSetField(Tags.TargetCompID) ? er.Header.GetString(Tags.TargetCompID) : cfg.TargetCompID; if (er.IsSetNoMiscFees()) { int ocorr = er.GetInt(Tags.NoMiscFees);// noMiscFees.getValue(); for (uint i = 0; i < ocorr; i++) { EmolumentoInfo emol = new EmolumentoInfo(); Group feeGroup = er.GetGroup((int)i, Tags.NoMiscFees); emol.Valor = Convert.ToDecimal(feeGroup.IsSetField(Tags.MiscFeeAmt) ? feeGroup.GetString(Tags.MiscFeeAmt) : "0"); emol.BaseEmolumento = Convert.ToInt32(feeGroup.IsSetField(Tags.MiscFeeBasis) ? feeGroup.GetString(Tags.MiscFeeBasis) : "0"); emol.Currency = feeGroup.GetString(Tags.MiscFeeCurr); emol.Tipo = (EmolumentoTipoEnum)feeGroup.GetInt(Tags.MiscFeeType); } } // Adicionando informações de acompanhamento ao OrdemInfo order.Acompanhamentos.Clear(); order.Acompanhamentos.Add(acompanhamento); return(order); } catch (Exception ex) { logger.Error("Fix44ExecutionReport2OrdemInfo(): " + ex.Message, ex); } return(null); }
public bool AlterarOrdem(OrdemInfo ordem) { //Cria a mensagem FIX de NewOrderSingle QuickFix.FIX42.OrderCancelReplaceRequest ordercrr = new QuickFix.FIX42.OrderCancelReplaceRequest(); ordercrr.Set(new Account(ordem.Account.ToString())); ordercrr.Set(new Symbol(ordem.Symbol)); ordercrr.Set(new ClOrdID(ordem.ClOrdID)); ordercrr.Set(new OrigClOrdID(ordem.OrigClOrdID)); if (ordem.ExchangeNumberID != null && ordem.ExchangeNumberID.Length > 0) { ordercrr.Set(new OrderID(ordem.ExchangeNumberID)); } // Armazena ClOrdID em Memo (5149) para posterior referência nos tratamentos de retornos QuickFix.Fields.StringField field5149 = new QuickFix.Fields.StringField(5149, ordem.ClOrdID); ordercrr.SetField(field5149); //ordersingle.Set(new IDSource()); if (ordem.Side == OrdemDirecaoEnum.Venda) { ordercrr.Set(new Side(Side.SELL)); } else { ordercrr.Set(new Side(Side.BUY)); } TimeInForce tif = FixMessageUtilities.deOrdemValidadeParaTimeInForce(ordem.TimeInForce); if (tif != null) { ordercrr.Set(tif); } ordercrr.Set(new OrderQty(ordem.OrderQty)); if (ordem.TimeInForce == OrdemValidadeEnum.ValidoAteDeterminadaData) { DateTime expiredate = Convert.ToDateTime(ordem.ExpireDate); ordercrr.Set(new ExpireDate(expiredate.ToString("yyyyMMdd"))); } OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(ordem.OrdType); if (ordType != null) { ordercrr.Set(ordType); } // Verifica envio do preco switch (ordem.OrdType) { case OrdemTipoEnum.Limitada: case OrdemTipoEnum.MarketWithLeftOverLimit: case OrdemTipoEnum.StopLimitada: ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price))); break; case OrdemTipoEnum.StopStart: ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price))); ordercrr.Set(new StopPx(Convert.ToDecimal(ordem.StopPrice))); break; case OrdemTipoEnum.Mercado: case OrdemTipoEnum.OnClose: ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price))); break; default: ordercrr.Set(new Price(Convert.ToDecimal(ordem.Price))); break; } ordercrr.Set(new TransactTime(DateTime.Now)); ordercrr.Set(new HandlInst('1')); ordercrr.Set(new ExecBroker("227")); if (ordem.MaxFloor > 0) { ordercrr.Set(new MaxFloor(Convert.ToDecimal(ordem.MaxFloor))); } if (ordem.MinQty > 0) { ordercrr.Set(new MinQty(Convert.ToDecimal(ordem.MinQty))); } QuickFix.FIX42.OrderCancelReplaceRequest.NoAllocsGroup noAllocsGrp = new QuickFix.FIX42.OrderCancelReplaceRequest.NoAllocsGroup(); noAllocsGrp.Set(new AllocAccount("67")); ordercrr.AddGroup(noAllocsGrp); bool bRet = Session.SendToTarget(ordercrr, _session.SessionID); return(bRet); }
public bool AlterarOrdem(OrdemInfo ordem) { //Cria a mensagem FIX de NewOrderSingle QuickFix.FIX44.OrderCancelReplaceRequest orderCancelReplaceReq = new QuickFix.FIX44.OrderCancelReplaceRequest(); orderCancelReplaceReq.Set(new OrigClOrdID(ordem.OrigClOrdID)); if (ordem.Account > 0) { orderCancelReplaceReq.Set(new Account(ordem.Account.ToString())); } // Instrument Identification Block orderCancelReplaceReq.Set(new Symbol(ordem.Symbol)); orderCancelReplaceReq.Set(new SecurityID(ordem.SecurityID)); orderCancelReplaceReq.Set(new SecurityIDSource(SecurityIDSource.EXCHANGE_SYMBOL)); if (ordem.ExchangeNumberID != null && ordem.ExchangeNumberID.Length > 0) { orderCancelReplaceReq.Set(new OrderID(ordem.ExchangeNumberID)); } orderCancelReplaceReq.Set(new ClOrdID(ordem.ClOrdID)); //ordersingle.set(new IDSource()); if (ordem.Side == OrdemDirecaoEnum.Venda) { orderCancelReplaceReq.Set(new Side(Side.SELL)); } else { orderCancelReplaceReq.Set(new Side(Side.BUY)); } orderCancelReplaceReq.Set(new Price(Convert.ToDecimal(ordem.Price))); TimeInForce tif = FixMessageUtilities.deOrdemValidadeParaTimeInForce(ordem.TimeInForce); if (tif != null) { orderCancelReplaceReq.Set(tif); } orderCancelReplaceReq.Set(new OrderQty(ordem.OrderQty)); if (ordem.TimeInForce == OrdemValidadeEnum.ValidoAteDeterminadaData) { DateTime expiredate = Convert.ToDateTime(ordem.ExpireDate); orderCancelReplaceReq.Set(new ExpireDate(expiredate.ToString("yyyyMMdd"))); } OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(ordem.OrdType); if (ordType != null) { orderCancelReplaceReq.Set(ordType); } //if (ordem.OrdType == OrdemTipoEnum.StopLimitada ) //{ // ordersingle.set(new StopPx(ordem.StopPx)); //} orderCancelReplaceReq.Set(new TransactTime(DateTime.Now)); // Cliente QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup1 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); PartyIDGroup1.Set(new PartyID(ordem.ExecBroker)); PartyIDGroup1.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup1.Set(new PartyRole(PartyRole.ENTERING_TRADER)); // Corretora QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup2 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); PartyIDGroup2.Set(new PartyID("227")); PartyIDGroup2.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup2.Set(new PartyRole(PartyRole.ENTERING_FIRM)); // Location ID QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup3 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); if (ordem.SenderLocation != null && ordem.SenderLocation.Length > 0) { PartyIDGroup3.Set(new PartyID(ordem.SenderLocation)); } else { PartyIDGroup3.Set(new PartyID("GRA")); } PartyIDGroup3.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup3.Set(new PartyRole(54)); orderCancelReplaceReq.AddGroup(PartyIDGroup1); orderCancelReplaceReq.AddGroup(PartyIDGroup2); orderCancelReplaceReq.AddGroup(PartyIDGroup3); //BEI - 2012-Nov-14 if (ordem.ForeignFirm != null && ordem.ForeignFirm.Length > 0) { QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup4 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); PartyIDGroup4.Set(new PartyID(ordem.ForeignFirm)); PartyIDGroup4.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup4.Set(new PartyRole(PartyRole.FOREIGN_FIRM)); orderCancelReplaceReq.AddGroup(PartyIDGroup4); } if (ordem.Account > 0) { QuickFix.FIX44.OrderCancelReplaceRequest.NoAllocsGroup noAllocsGrp = new QuickFix.FIX44.OrderCancelReplaceRequest.NoAllocsGroup(); noAllocsGrp.Set(new AllocAccount(ordem.Account.ToString())); noAllocsGrp.Set(new AllocAcctIDSource(99)); orderCancelReplaceReq.AddGroup(noAllocsGrp); } //SelfTradeProtection - 2012-Nov-27 if (ordem.InvestorID != null && ordem.InvestorID.Length > 0) { QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup5 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); PartyIDGroup5.Set(new PartyID(ordem.InvestorID)); PartyIDGroup5.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup5.Set(new PartyRole(PartyRole.INVESTOR_ID)); orderCancelReplaceReq.AddGroup(PartyIDGroup5); } if (ordem.ExecutingTrader != null && ordem.ExecutingTrader.Length > 0) { QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup PartyIDGroup7 = new QuickFix.FIX44.OrderCancelReplaceRequest.NoPartyIDsGroup(); PartyIDGroup7.Set(new PartyID(ordem.ExecutingTrader)); PartyIDGroup7.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup7.Set(new PartyRole(PartyRole.EXECUTING_TRADER)); orderCancelReplaceReq.AddGroup(PartyIDGroup7); } // Memo Field if (ordem.Memo5149 != null && ordem.Memo5149.Length > 0) { if (ordem.Memo5149.Length > 50) { ordem.Memo5149 = ordem.Memo5149.Substring(0, 50); } StringField memo5149 = new StringField(5149, ordem.Memo5149); orderCancelReplaceReq.SetField(memo5149); } bool bRet = Session.SendToTarget(orderCancelReplaceReq, _session.SessionID); return(bRet); }
public bool EnviarOrdem(OrdemInfo ordem) { //Cria a mensagem FIX de NewOrderSingle QuickFix.FIX44.NewOrderSingle ordersingle = new QuickFix.FIX44.NewOrderSingle(); if (ordem.Account > 0) { ordersingle.Set(new Account(ordem.Account.ToString())); } // Instrument Identification Block ordersingle.Set(new Symbol(ordem.Symbol)); ordersingle.Set(new SecurityID(ordem.SecurityID)); ordersingle.Set(new SecurityIDSource(SecurityIDSource.EXCHANGE_SYMBOL)); ordersingle.Set(new ClOrdID(ordem.ClOrdID)); if (ordem.Side == OrdemDirecaoEnum.Venda) { ordersingle.Set(new Side(Side.SELL)); } else { ordersingle.Set(new Side(Side.BUY)); } TimeInForce tif = FixMessageUtilities.deOrdemValidadeParaTimeInForce(ordem.TimeInForce); if (tif != null) { ordersingle.Set(tif); } ordersingle.Set(new OrderQty(ordem.OrderQty)); if (ordem.TimeInForce == OrdemValidadeEnum.ValidoAteDeterminadaData) { DateTime expiredate = Convert.ToDateTime(ordem.ExpireDate); ordersingle.Set(new ExpireDate(expiredate.ToString("yyyyMMdd"))); } OrdType ordType = FixMessageUtilities.deOrdemTipoParaOrdType(ordem.OrdType); if (ordType != null) { ordersingle.Set(ordType); } // Verifica envio do preco switch (ordem.OrdType) { case OrdemTipoEnum.Limitada: case OrdemTipoEnum.MarketWithLeftOverLimit: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); break; case OrdemTipoEnum.StopLimitada: case OrdemTipoEnum.StopStart: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); ordersingle.Set(new StopPx(Convert.ToDecimal(ordem.StopPrice))); break; case OrdemTipoEnum.Mercado: case OrdemTipoEnum.OnClose: break; default: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); break; } ordersingle.Set(new TransactTime(DateTime.Now)); ordersingle.Set(new HandlInst('1')); if (ordem.MaxFloor > 0) { ordersingle.Set(new MaxFloor(Convert.ToDecimal(ordem.MaxFloor))); } if (ordem.MinQty > 0) { ordersingle.Set(new MinQty(Convert.ToDecimal(ordem.MinQty))); } // Cliente QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup1 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); //PartyIDGroup1.set(new PartyID(ordem.Account.ToString())); PartyIDGroup1.Set(new PartyID(ordem.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)); // Location ID QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup3 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); if (ordem.SenderLocation != null && ordem.SenderLocation.Length > 0) { PartyIDGroup3.Set(new PartyID(ordem.SenderLocation)); } else { PartyIDGroup3.Set(new PartyID("GRA")); } PartyIDGroup3.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup3.Set(new PartyRole(PartyRole.SENDER_LOCATION)); ordersingle.AddGroup(PartyIDGroup1); ordersingle.AddGroup(PartyIDGroup2); ordersingle.AddGroup(PartyIDGroup3); //BEI - 2012-Nov-13 if (ordem.ForeignFirm != null && ordem.ForeignFirm.Length > 0) { QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup5 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup5.Set(new PartyID(ordem.ForeignFirm)); PartyIDGroup5.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup5.Set(new PartyRole(PartyRole.FOREIGN_FIRM)); ordersingle.AddGroup(PartyIDGroup5); } //SelfTradeProtection - 2012-Nov-27 if (ordem.InvestorID != null && ordem.InvestorID.Length > 0) { QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup6 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup6.Set(new PartyID(ordem.InvestorID)); PartyIDGroup6.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup6.Set(new PartyRole(PartyRole.INVESTOR_ID)); ordersingle.AddGroup(PartyIDGroup6); } if (ordem.ExecutingTrader != null && ordem.ExecutingTrader.Length > 0) { QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup PartyIDGroup7 = new QuickFix.FIX44.NewOrderSingle.NoPartyIDsGroup(); PartyIDGroup7.Set(new PartyID(ordem.ExecutingTrader)); PartyIDGroup7.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup7.Set(new PartyRole(PartyRole.EXECUTING_TRADER)); ordersingle.AddGroup(PartyIDGroup7); } //if (ordem.Account > 0) //{ // QuickFix.FIX44.NewOrderSingle.NoAllocsGroup noAllocsGrp = new QuickFix.FIX44.NewOrderSingle.NoAllocsGroup(); // noAllocsGrp.Set(new AllocAccount(ordem.Account.ToString())); // noAllocsGrp.Set(new AllocAcctIDSource(99)); // ordersingle.AddGroup(noAllocsGrp); //} if (ordem.PositionEffect != null && ordem.PositionEffect.Equals("C")) { ordersingle.Set(new PositionEffect('C')); } // Memo Field if (ordem.Memo5149 != null && ordem.Memo5149.Length > 0) { if (ordem.Memo5149.Length > 50) { ordem.Memo5149 = ordem.Memo5149.Substring(0, 50); } StringField memo5149 = new StringField(5149, ordem.Memo5149); ordersingle.SetField(memo5149); } // AccountType if (ordem.AcountType == ContaTipoEnum.REMOVE_ACCOUNT_INFORMATION) { IntField int581 = new IntField(581, 38); ordersingle.SetField(int581); } else if (ordem.AcountType == ContaTipoEnum.GIVE_UP_LINK_IDENTIFIER) { IntField int581 = new IntField(581, 40); ordersingle.SetField(int581); } bool bRet = Session.SendToTarget(ordersingle, _session.SessionID); return(bRet); }