/// <summary> /// Creates a FIX4.4 OrderCancelRequest message for Forexware /// </summary> /// <param name="order"></param> /// <returns></returns> public QuickFix.FIX44.OrderCancelRequest OrderCancelRequest(Order order) { QuickFix.FIX44.OrderCancelRequest orderCancelRequest = new QuickFix.FIX44.OrderCancelRequest(); QuickFix.Fields.ClOrdID clOrdId = new QuickFix.Fields.ClOrdID(DateTime.Now.ToString(("yyMMddHmsfff"))); orderCancelRequest.SetField(clOrdId); QuickFix.Fields.OrigClOrdID origClOrdId = new QuickFix.Fields.OrigClOrdID(order.OrderID); orderCancelRequest.SetField(origClOrdId); var account = new QuickFix.Fields.Account(_account); orderCancelRequest.SetField(account); QuickFix.Fields.Symbol symbol = new QuickFix.Fields.Symbol(order.Security.Symbol); orderCancelRequest.SetField(symbol); //set order side if (order.OrderSide == Constants.OrderSide.BUY) { orderCancelRequest.Set(new Side(Side.BUY)); } else if (order.OrderSide == Constants.OrderSide.SELL) { orderCancelRequest.Set(new Side(Side.SELL)); } QuickFix.Fields.TransactTime transactTime = new QuickFix.Fields.TransactTime(order.OrderDateTime); orderCancelRequest.SetField(transactTime); //QuickFix.Fields.Product product = new QuickFix.Fields.Product(FixCommon.Constants.Product.Currency); //orderCancelRequest.SetField(product); return(orderCancelRequest); }
/// <summary> /// Creates a FIX4.4 OrderCancelRequest message for Fxcm /// </summary> /// <param name="order"></param> /// <returns></returns> public QuickFix.FIX44.OrderCancelRequest OrderCancelRequest(Order order) { char orderSide = default(char); if (order.OrderSide == Constants.OrderSide.BUY) { orderSide = Side.BUY; } else if (order.OrderSide == Constants.OrderSide.SELL) { orderSide = Side.SELL; } if (orderSide.Equals(default(char))) { _logger.Error("Invalid Order Side", _type.FullName, "OrderCancelRequest"); return(null); } QuickFix.FIX44.OrderCancelRequest orderCancelRequest = new QuickFix.FIX44.OrderCancelRequest(); QuickFix.Fields.OrderID orderId = new QuickFix.Fields.OrderID(order.BrokerOrderID); orderCancelRequest.SetField(orderId); 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); var account = new QuickFix.Fields.Account(_account); orderCancelRequest.SetField(account); QuickFix.Fields.Symbol symbol = new QuickFix.Fields.Symbol(order.Security.Symbol); orderCancelRequest.SetField(symbol); QuickFix.Fields.Side side = new QuickFix.Fields.Side(orderSide); orderCancelRequest.SetField(side); QuickFix.Fields.TransactTime transactTime = new QuickFix.Fields.TransactTime(order.OrderDateTime); orderCancelRequest.SetField(transactTime); QuickFix.Fields.Product product = new QuickFix.Fields.Product(FixCommon.Constants.Product.Currency); orderCancelRequest.SetField(product); return(orderCancelRequest); }
public bool CancelarOrdem(OrdemCancelamentoInfo orderCancelInfo, long ini = 0, long fim = 0, long oriini = 0, long orifim = 0, int delay = 0, string mnemonic = "") { //Cria a mensagem FIX de OrderCancelRequest QuickFix.FIX44.OrderCancelRequest orderCancel = new QuickFix.FIX44.OrderCancelRequest(); if (orderCancelInfo.Account > 0) { orderCancel.Set(new Account(orderCancelInfo.Account.ToString())); } if (!string.IsNullOrEmpty(mnemonic)) { orderCancel.SetField(new Account(mnemonic), true); } orderCancel.Set(new OrigClOrdID(orderCancelInfo.OrigClOrdID)); orderCancel.Set(new ClOrdID(orderCancelInfo.ClOrdID)); if (orderCancelInfo.OrderID != null && orderCancelInfo.OrderID.Length > 0) { orderCancel.Set(new OrderID(orderCancelInfo.OrderID)); } // Instrument Identification Block orderCancel.Set(new Symbol(orderCancelInfo.Symbol)); orderCancel.Set(new SecurityID(orderCancelInfo.SecurityID)); orderCancel.Set(new SecurityIDSource(SecurityIDSource.EXCHANGE_SYMBOL)); if (orderCancelInfo.Side == OrdemDirecaoEnum.Venda) { orderCancel.Set(new Side(Side.SELL)); } else { orderCancel.Set(new Side(Side.BUY)); } orderCancel.Set(new TransactTime(DateTime.Now)); //ATP - 2012-10-29 //Qtde de contratos/papeis a serem cancelados orderCancel.Set(new OrderQty(orderCancelInfo.OrderQty)); // Cliente QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup PartyIDGroup1 = new QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup(); PartyIDGroup1.Set(new PartyID(orderCancelInfo.ExecBroker)); PartyIDGroup1.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup1.Set(new PartyRole(PartyRole.ENTERING_TRADER)); // Corretora QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup PartyIDGroup2 = new QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup(); PartyIDGroup2.Set(new PartyID("227")); PartyIDGroup2.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup2.Set(new PartyRole(PartyRole.ENTERING_FIRM)); QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup PartyIDGroup3 = new QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup(); if (orderCancelInfo.SenderLocation != null && orderCancelInfo.SenderLocation.Length > 0) { PartyIDGroup3.Set(new PartyID(orderCancelInfo.SenderLocation)); } else { PartyIDGroup3.Set(new PartyID("GRA")); } PartyIDGroup3.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup3.Set(new PartyRole(54)); orderCancel.AddGroup(PartyIDGroup1); orderCancel.AddGroup(PartyIDGroup2); orderCancel.AddGroup(PartyIDGroup3); //BEI - 2012-Nov-14 if (orderCancelInfo.ForeignFirm != null && orderCancelInfo.ForeignFirm.Length > 0) { QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup PartyIDGroup4 = new QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup(); PartyIDGroup4.Set(new PartyID(orderCancelInfo.ForeignFirm)); PartyIDGroup4.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup4.Set(new PartyRole(PartyRole.FOREIGN_FIRM)); orderCancel.AddGroup(PartyIDGroup4); } if (orderCancelInfo.ExecutingTrader != null && orderCancelInfo.ExecutingTrader.Length > 0) { QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup PartyIDGroup7 = new QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup(); PartyIDGroup7.Set(new PartyID(orderCancelInfo.ExecutingTrader)); PartyIDGroup7.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup7.Set(new PartyRole(PartyRole.EXECUTING_TRADER)); orderCancel.AddGroup(PartyIDGroup7); } // Memo Field if (orderCancelInfo.Memo5149 != null && orderCancelInfo.Memo5149.Length > 0) { if (orderCancelInfo.Memo5149.Length > 50) { orderCancelInfo.Memo5149 = orderCancelInfo.Memo5149.Substring(0, 50); } StringField memo5149 = new StringField(5149, orderCancelInfo.Memo5149); orderCancel.SetField(memo5149); } bool bRet = false; 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()); orderCancel.ClOrdID = xx; orderCancel.OrigClOrdID = xx2; bRet = Session.SendToTarget(orderCancel, _session.SessionID); if (!bRet) { logger.Info("erro"); break; } if (0 != delay) { Thread.Sleep(delay); } ini++; oriini++; //System.Windows.Forms.Application.DoEvents(); } logger.Info("=====================================> FIM CANCELAR ORDEM========> Qtd: " + times); } else { bRet = Session.SendToTarget(orderCancel, _session.SessionID); } return(bRet); }
public bool CancelarOrdem(OrdemCancelamentoInfo orderCancelInfo) { //Cria a mensagem FIX de OrderCancelRequest QuickFix.FIX44.OrderCancelRequest orderCancel = new QuickFix.FIX44.OrderCancelRequest(); if (orderCancelInfo.Account > 0) { orderCancel.Set(new Account(orderCancelInfo.Account.ToString())); } orderCancel.Set(new OrigClOrdID(orderCancelInfo.OrigClOrdID)); orderCancel.Set(new ClOrdID(orderCancelInfo.ClOrdID)); if (orderCancelInfo.OrderID != null && orderCancelInfo.OrderID.Length > 0) { orderCancel.Set(new OrderID(orderCancelInfo.OrderID)); } // Instrument Identification Block orderCancel.Set(new Symbol(orderCancelInfo.Symbol)); orderCancel.Set(new SecurityID(orderCancelInfo.SecurityID)); orderCancel.Set(new SecurityIDSource(SecurityIDSource.EXCHANGE_SYMBOL)); if (orderCancelInfo.Side == OrdemDirecaoEnum.Venda) { orderCancel.Set(new Side(Side.SELL)); } else { orderCancel.Set(new Side(Side.BUY)); } orderCancel.Set(new TransactTime(DateTime.Now)); //ATP - 2012-10-29 //Qtde de contratos/papeis a serem cancelados orderCancel.Set(new OrderQty(orderCancelInfo.OrderQty)); // Cliente QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup PartyIDGroup1 = new QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup(); PartyIDGroup1.Set(new PartyID(orderCancelInfo.ExecBroker)); PartyIDGroup1.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup1.Set(new PartyRole(PartyRole.ENTERING_TRADER)); // Corretora QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup PartyIDGroup2 = new QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup(); PartyIDGroup2.Set(new PartyID("227")); PartyIDGroup2.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup2.Set(new PartyRole(PartyRole.ENTERING_FIRM)); QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup PartyIDGroup3 = new QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup(); if (orderCancelInfo.SenderLocation != null && orderCancelInfo.SenderLocation.Length > 0) { PartyIDGroup3.Set(new PartyID(orderCancelInfo.SenderLocation)); } else { PartyIDGroup3.Set(new PartyID("GRA")); } PartyIDGroup3.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup3.Set(new PartyRole(54)); orderCancel.AddGroup(PartyIDGroup1); orderCancel.AddGroup(PartyIDGroup2); orderCancel.AddGroup(PartyIDGroup3); //BEI - 2012-Nov-14 if (orderCancelInfo.ForeignFirm != null && orderCancelInfo.ForeignFirm.Length > 0) { QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup PartyIDGroup4 = new QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup(); PartyIDGroup4.Set(new PartyID(orderCancelInfo.ForeignFirm)); PartyIDGroup4.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup4.Set(new PartyRole(PartyRole.FOREIGN_FIRM)); orderCancel.AddGroup(PartyIDGroup4); } if (orderCancelInfo.ExecutingTrader != null && orderCancelInfo.ExecutingTrader.Length > 0) { QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup PartyIDGroup7 = new QuickFix.FIX44.OrderCancelRequest.NoPartyIDsGroup(); PartyIDGroup7.Set(new PartyID(orderCancelInfo.ExecutingTrader)); PartyIDGroup7.Set(new PartyIDSource(PartyIDSource.PROPRIETARY_CUSTOM_CODE)); PartyIDGroup7.Set(new PartyRole(PartyRole.EXECUTING_TRADER)); orderCancel.AddGroup(PartyIDGroup7); } // Memo Field if (orderCancelInfo.Memo5149 != null && orderCancelInfo.Memo5149.Length > 0) { if (orderCancelInfo.Memo5149.Length > 50) { orderCancelInfo.Memo5149 = orderCancelInfo.Memo5149.Substring(0, 50); } StringField memo5149 = new StringField(5149, orderCancelInfo.Memo5149); orderCancel.SetField(memo5149); } bool bRet = Session.SendToTarget(orderCancel, _session.SessionID); return(bRet); }