/// <summary> /// Creates a FIX4.2 OrderCancelRequest message for Currenex /// </summary> /// <param name="order"></param> /// <returns></returns> public QuickFix.FIX42.OrderCancelRequest OrderCancelRequest(Order order) { QuickFix.FIX42.OrderCancelRequest orderCancelRequest = new QuickFix.FIX42.OrderCancelRequest(); QuickFix.Fields.OrigClOrdID origClOrdId = new QuickFix.Fields.OrigClOrdID(order.OrderID); orderCancelRequest.SetField(origClOrdId); QuickFix.Fields.ClOrdID clOrdId = new QuickFix.Fields.ClOrdID(DateTime.Now.ToString(("yyMMddHmsfff"))); orderCancelRequest.SetField(clOrdId); QuickFix.Fields.Symbol symbol = new QuickFix.Fields.Symbol(order.Security.Symbol); orderCancelRequest.SetField(symbol); QuickFix.Fields.Side side = new QuickFix.Fields.Side(Convert.ToChar(order.OrderSide)); orderCancelRequest.SetField(side); QuickFix.Fields.TransactTime transactTime = new QuickFix.Fields.TransactTime(order.OrderDateTime); orderCancelRequest.SetField(transactTime); QuickFix.Fields.OrdType ordType = new QuickFix.Fields.OrdType('F'); orderCancelRequest.SetField(ordType); return(orderCancelRequest); }
public bool CancelarOrdem(OrdemCancelamentoInfo 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.OrderCancelRequest ordercrr = new QuickFix.FIX42.OrderCancelRequest(); 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)); // 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 = 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 CANCELAR 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 CANCELAR ORDEM========> Qtd: " + times); } else { bRet = Session.SendToTarget(ordercrr, _session.SessionID); } return(bRet); }
public bool CancelarOrdem(OrdemCancelamentoInfo ordem) { //Cria a mensagem FIX de NewOrderSingle QuickFix.FIX42.OrderCancelRequest ordercrr = new QuickFix.FIX42.OrderCancelRequest(); 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)); // 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); }