public void UnwrapMessage_AsMsgType_Ok_Sandbox() { // arrange var jsonFixMsg = new JsonFixMessageReceived { localPseudoHeader = "myPseudoHeader", messageTypeCode35 = "D", rawFixPayload = "8=FIX.4.2\u00019=00\u000135=D\u000149=Sender\u000156=Target\u000134=0\u000152=99990909-17:17:17.777\u000154=1\u000155=ABC\u000111=BUY000000001\u000138=1000\u000140=2\u000144=1001.000\u000159=3\u0001117=A001\u000146=A001\u000110=000\u0001" }; // act QuickFix.Message fixMsg = _jsonFixWrapper.Unwrap(jsonFixMsg); // QuickFix.FIX42.NewOrderSingle newOrderD = new QuickFix.FIX42.NewOrderSingle(); QuickFix.FIX42.NewOrderSingle newOrderD = _jsonFixWrapper.UnwrapAsType <NewOrderSingle>(jsonFixMsg); // issue how to downcast // assert var expectedTicker = "ABC"; var expectedTarget = "Target"; var actualTarget = newOrderD.Header.GetField(new QuickFix.Fields.TargetCompID()).getValue(); var actualTicker = newOrderD.Header.GetField(new QuickFix.Fields.Symbol()).getValue(); Assert.Equal(expectedTicker, actualTicker); Assert.Equal(expectedTarget, actualTarget); }
public bool DummyTest() { try { QuickFix.FIX42.NewOrderSingle nos42 = new QuickFix.FIX42.NewOrderSingle(); nos42.SetField(new Account("319400")); nos42.SetField(new OrderQty(1M)); nos42.SetField(new OrdType('1')); nos42.SetField(new ClOrdID(DateTime.Now.ToString("hhMMss"))); nos42.SetField(new Currency("BRL")); nos42.SetField(new SecurityID("B7XL5Q9")); nos42.SetField(new HandlInst('1')); nos42.SetField(new IDSource("2")); nos42.SetField(new Side('1')); nos42.SetField(new Symbol("OIBR4F")); nos42.SetField(new SecurityExchange("BZ")); nos42.SetField(new TimeInForce('1')); nos42.SetField(new TransactTime(DateTime.Now)); bool bRet = Session.SendToTarget(nos42, _session.SessionID); return(bRet); } catch { return(false); } }
public void OnMessage(QuickFix.FIX42.NewOrderSingle order, SessionID sessionId) { Console.WriteLine("ClOrdID: {0}", order.ClOrdID); Console.WriteLine("HandlInst: {0}", order.HandlInst); Console.WriteLine("Symbol: {0}", order.Symbol); Console.WriteLine("Side: {0}", order.Side); Console.WriteLine("TransactTime: {0}", order.TransactTime); Console.WriteLine("OrdType: {0}", order.OrdType); Console.WriteLine("Amount: {0}", order.OrderQty); //Console.WriteLine("Duration: {0}", order.); // Duration??? Console.WriteLine("Price: {0}", order.Price); //Console.WriteLine("Limit Price: {0}", order.StopPx); //Console.WriteLine("Notes: {0}", order.); // Notes??? }
public QuickFix.FIX42.NewOrderSingle NewOrderSingle() { var order = new QuickFix.FIX42.NewOrderSingle( new ClOrdID("1234"), new HandlInst('1'), new Symbol("ZVZZT"), new Side(Side.BUY), new TransactTime(DateTime.Now), new OrdType(OrdType.MARKET) ); order.Price = new Price(new decimal(25.05)); order.Account = new Account("123456789"); order.OrderQty = new OrderQty(new decimal(500)); //order.StopPx = new StopPx(new decimal(28.00)); return(order); }
public void WrapMessage_Ok() { // get fixMessage // wrap into jsonfix // assert on jsonfix order var orderQty = 10m; var ticker = "AAPL"; var clientOrderId = "0001"; var handlingInst = ""; var transactTime = new DateTime(2018, 10, 13).Date; // arrange var fm = new QuickFix.FIX42.NewOrderSingle( new QuickFix.Fields.ClOrdID(clientOrderId), new QuickFix.Fields.HandlInst(QuickFix.Fields.HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE_NO_BROKER_INTERVENTION), new QuickFix.Fields.Symbol(ticker), new QuickFix.Fields.Side(QuickFix.Fields.Side.BUY), new QuickFix.Fields.TransactTime(transactTime), new QuickFix.Fields.OrdType(QuickFix.Fields.OrdType.MARKET) ); fm.SetField(new QuickFix.Fields.OrderQty(orderQty)); // dbg Console.WriteLine($"fix message fm: {fm.ToString()}"); // act var jsonFixMsg = _jsonFixWrapper.Wrap(fm, "myHeaderInfo"); // assert var rawfix = jsonFixMsg.rawFixPayload; Assert.False(string.IsNullOrEmpty(rawfix)); var separator = _jsonFixWrapper.GetSeparator(); var byParts = rawfix.Split(separator).ToList(); var symbolPart = byParts.FirstOrDefault(x => x.StartsWith("55")); Assert.True(symbolPart.EndsWith(ticker)); Assert.Equal("myHeaderInfo", jsonFixMsg.localPseudoHeader); }
// public bool EnviarOrdemCross(OrdemCrossInfo info) { return false; } public bool EnviarOrdem(OrdemInfo ordem, long ini = 0, long fim = 0, int delay = 0, string mnemonic = "", string senderSubID = "", string extraTags = "") { //Cria a mensagem FIX de NewOrderSingle QuickFix.FIX42.NewOrderSingle ordersingle = new QuickFix.FIX42.NewOrderSingle(); ordersingle.Set(new Account(ordem.Account.ToString())); if (!string.IsNullOrEmpty(mnemonic)) { ordersingle.SetField(new Account(mnemonic), true); } if (!string.IsNullOrEmpty(senderSubID)) { ordersingle.Header.SetField(new SenderSubID(senderSubID)); } ordersingle.Set(new Symbol(ordem.Symbol)); ordersingle.Set(new ClOrdID(ordem.ClOrdID)); // Armazena ClOrdID em Memo (5149) para posterior referência nos tratamentos de retornos QuickFix.Fields.StringField field5149 = new QuickFix.Fields.StringField(5149, ordem.ClOrdID); ordersingle.SetField(field5149); //ordersingle.Set(new IDSource()); 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); } // Para versao 4.2, os novos tipos de OrdType a serem enviados (5, A ou B); if (!string.IsNullOrEmpty(ordem.Memo5149)) { ordersingle.SetField(new OrdType(Convert.ToChar(ordem.Memo5149)), true); } // 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: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); break; default: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); break; } ordersingle.Set(new TransactTime(DateTime.Now)); ordersingle.Set(new HandlInst('1')); ordersingle.Set(new ExecBroker("227")); if (ordem.MaxFloor > 0) { ordersingle.Set(new MaxFloor(Convert.ToDecimal(ordem.MaxFloor))); } if (ordem.MinQty > 0) { ordersingle.Set(new MinQty(Convert.ToDecimal(ordem.MinQty))); } // 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]); ordersingle.SetField(fld); } } } QuickFix.FIX42.NewOrderSingle.NoAllocsGroup noAllocsGrp = new QuickFix.FIX42.NewOrderSingle.NoAllocsGroup(); noAllocsGrp.Set(new AllocAccount("67")); ordersingle.AddGroup(noAllocsGrp); bool bRet = false; if (ini == 0) { bRet = Session.SendToTarget(ordersingle, _session.SessionID); } else { long times = fim - ini; logger.Info("=====================================> INICIO ========> Qtd: " + times); for (long i = 0; i < times; 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++; } logger.Info("=====================================> FIM ========> Qtd: " + times); } return(bRet); }
public void Run() { QuickFix.FIX42.NewOrderSingle order = NewOrderSingle(); order.Header.GetField(Tags.BeginString); SendMessage(order); }
/// <summary> /// Creates a FIX4.2 NewOrderSingle message for Currenex /// </summary> /// <param name="order"></param> /// <returns></returns> public QuickFix.FIX42.NewOrderSingle NewOrderSingle(Order order) { var newOrderSingle = new QuickFix.FIX42.NewOrderSingle(); var clOrdId = new QuickFix.Fields.ClOrdID(order.OrderID); newOrderSingle.SetField(clOrdId); var securityType = new QuickFix.Fields.SecurityType(FixCommon.Constants.SecurityType.ForeignExchangeContract); newOrderSingle.SetField(securityType); var symbol = new QuickFix.Fields.Symbol(order.Security.Symbol); newOrderSingle.SetField(symbol); //set order side if (order.OrderSide == Constants.OrderSide.BUY) { newOrderSingle.Set(new Side(Side.BUY)); } else if (order.OrderSide == Constants.OrderSide.SELL) { newOrderSingle.Set(new Side(Side.SELL)); } var transactTime = new QuickFix.Fields.TransactTime(order.OrderDateTime); newOrderSingle.SetField(transactTime); var orderQty = new QuickFix.Fields.OrderQty(order.OrderSize); newOrderSingle.SetField(orderQty); var minQty = new QuickFix.Fields.MinQty(order.OrderSize); newOrderSingle.SetField(minQty); //only limit and market orders are supported. if (order.GetType() == typeof(LimitOrder)) { newOrderSingle.Set(new OrdType('F')); newOrderSingle.Set(new Price(((LimitOrder)order).LimitPrice)); } else if (order.GetType() == typeof(MarketOrder)) { newOrderSingle.Set(new OrdType('C')); } //if (order.OrderSize != order.OrderSizeToShow) //{ // var maxShow = new QuickFix.Fields.MaxShow(order.OrderSizeToShow); // newOrderSingle.SetField(maxShow); //} var tif = new QuickFix.Fields.TimeInForce(FixCommon.Converter.ConvertTif.GetFixValue(order.OrderTif)); newOrderSingle.SetField(tif); var execInst = new QuickFix.Fields.ExecInst(ExecInst.BEST_EXECUTION); newOrderSingle.SetField(execInst); var currency = new QuickFix.Fields.Currency(order.OrderCurrency); newOrderSingle.SetField(currency); var handlInst = new QuickFix.Fields.HandlInst(HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE); newOrderSingle.SetField(handlInst); return(newOrderSingle); }
public bool EnviarOrdem(OrdemInfo ordem) { //Cria a mensagem FIX de NewOrderSingle QuickFix.FIX42.NewOrderSingle ordersingle = new QuickFix.FIX42.NewOrderSingle(); ordersingle.Set(new Account(ordem.Account.ToString())); ordersingle.Set(new Symbol(ordem.Symbol)); ordersingle.Set(new ClOrdID(ordem.ClOrdID)); // Armazena ClOrdID em Memo (5149) para posterior referência nos tratamentos de retornos QuickFix.Fields.StringField field5149 = new QuickFix.Fields.StringField(5149, ordem.ClOrdID); ordersingle.SetField(field5149); //ordersingle.Set(new IDSource()); 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: case OrdemTipoEnum.StopLimitada: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); break; 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: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); break; default: ordersingle.Set(new Price(Convert.ToDecimal(ordem.Price))); break; } ordersingle.Set(new TransactTime(DateTime.Now)); ordersingle.Set(new HandlInst('1')); ordersingle.Set(new ExecBroker("227")); if (ordem.MaxFloor > 0) { ordersingle.Set(new MaxFloor(Convert.ToDecimal(ordem.MaxFloor))); } if (ordem.MinQty > 0) { ordersingle.Set(new MinQty(Convert.ToDecimal(ordem.MinQty))); } QuickFix.FIX42.NewOrderSingle.NoAllocsGroup noAllocsGrp = new QuickFix.FIX42.NewOrderSingle.NoAllocsGroup(); noAllocsGrp.Set(new AllocAccount("67")); ordersingle.AddGroup(noAllocsGrp); bool bRet = Session.SendToTarget(ordersingle, _session.SessionID); return(bRet); }