public void HandleExecutionReport(QuickFix.FIX44.ExecutionReport msg) { try { string execId = msg.ExecID.Obj; //string transType = FixEnumTranslator.Translate(msg.ExecType); string execType = FixEnumTranslator.Translate(msg.ExecType); Trace.WriteLine("EVM: Handling ExecutionReport: " + execId + " / " + execType); ExecutionRecord exRec = new ExecutionRecord( msg.ExecID.Obj, msg.OrderID.Obj, string.Empty, execType, msg.Symbol.Obj, FixEnumTranslator.Translate(msg.Side)); exRec.LeavesQty = msg.LeavesQty.getValue(); exRec.TotalFilledQty = msg.CumQty.getValue(); exRec.LastQty = msg.LastQty.getValue(); SmartDispatcher.Invoke(new Action <ExecutionRecord>(AddExecution), exRec); } catch (Exception e) { Trace.WriteLine(e.ToString()); } }
public void OnMessage(QuickFix.FIX44.NewOrderSingle n, SessionID s) { Symbol symbol = n.Symbol; Side side = n.Side; OrdType ordType = n.OrdType; OrderQty orderQty = n.OrderQty; Price price = new Price(DEFAULT_MARKET_PRICE); ClOrdID clOrdID = n.ClOrdID; switch (ordType.getValue()) { case OrdType.LIMIT: price = n.Price; if (price.Obj == 0) { throw new IncorrectTagValue(price.Tag); } break; case OrdType.MARKET: break; default: throw new IncorrectTagValue(ordType.Tag); } QuickFix.FIX44.ExecutionReport exReport = new QuickFix.FIX44.ExecutionReport( new OrderID(GenOrderID()), new ExecID(GenExecID()), new ExecType(ExecType.FILL), new OrdStatus(OrdStatus.FILLED), symbol, //shouldn't be here? side, new LeavesQty(0), new CumQty(orderQty.getValue()), new AvgPx(price.getValue())); exReport.Set(clOrdID); exReport.Set(symbol); exReport.Set(orderQty); exReport.Set(new LastQty(orderQty.getValue())); exReport.Set(new LastPx(price.getValue())); if (n.IsSetAccount()) { exReport.SetField(n.Account); } try { Session.SendToTarget(exReport, s); } catch (SessionNotFound ex) { Console.WriteLine("==session not found exception!=="); Console.WriteLine(ex.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void OnMessage(QuickFix.FIX44.ExecutionReport msg, QuickFix.SessionID s) { if (Fix44ExecReportEvent != null) { Fix44ExecReportEvent(msg); } }
public void OnMessage(QuickFix.FIX44.NewOrderSingle n, SessionID s) { Console.WriteLine("* Got a NewOrderSingle. Responding with an ExecutionReport."); Symbol symbol = n.Symbol; Side side = n.Side; OrdType ordType = n.OrdType; OrderQty orderQty = n.OrderQty; Price price = new Price(DEFAULT_MARKET_PRICE); ClOrdID clOrdID = n.ClOrdID; switch (ordType.getValue()) { case OrdType.LIMIT: price = n.Price; if (price.Obj == 0) throw new IncorrectTagValue(price.Tag); break; case OrdType.MARKET: break; default: throw new IncorrectTagValue(ordType.Tag); } QuickFix.FIX44.ExecutionReport exReport = new QuickFix.FIX44.ExecutionReport( new OrderID(GenOrderID()), new ExecID(GenExecID()), new ExecType(ExecType.FILL), new OrdStatus(OrdStatus.FILLED), symbol, //shouldn't be here? side, new LeavesQty(0), new CumQty(orderQty.getValue()), new AvgPx(price.getValue())); exReport.Set(clOrdID); exReport.Set(symbol); exReport.Set(orderQty); exReport.Set(new LastQty(orderQty.getValue())); exReport.Set(new LastPx(price.getValue())); if (n.IsSetAccount()) exReport.SetField(n.Account); try { Session.SendToTarget(exReport, s); } catch (SessionNotFound ex) { Console.WriteLine("==session not found exception!=="); Console.WriteLine(ex.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void OneIncomingExecution() { UnitTestContext context = new UnitTestContext(); context.Login(); ExecutionViewModel vm = new ExecutionViewModel(context.App); QuickFix.FIX44.ExecutionReport ex = CreateExReport("order1", "exec1", QuickFix.Fields.ExecTransType.NEW, QuickFix.Fields.ExecType.NEW, QuickFix.Fields.OrdStatus.NEW, "IBM", QuickFix.Fields.Side.BUY, 1.23m, 4.56m, 7.89m); context.App.FromApp(ex, context.Session.SessionID); Assert.AreEqual(1, vm.Executions.Count); }
public void ToXMLWithGroupsTest() { var dd = new QuickFix.DataDictionary.DataDictionary(); dd.Load(Path.Combine(TestContext.CurrentContext.TestDirectory, "spec", "fix", "FIX44.xml")); string[] msgFields = { // header "8=FIX.4.4", "9=638", "35=8", "34=360", "49=BLPTSOX", "52=20130321-15:21:23", "56=THINKTSOX", "57=6804469", "128=ZERO", // non-group body fields "6=122.255", "11=61101189", "14=1990000", "15=GBP", "17=VCON:20130321:50018:5:12", "22=4", "31=122.255", "32=1990000", "37=116", "38=1990000", "39=2", "48=GB0032452392", "54=1", "55=[N/A]", "60=20130321-15:21:23", "64=20130322", "75=20130321", "106=UK TSY 4 1/4% 2036", "118=2436321.85", "150=F", "151=0", "157=15", "159=3447.35", "192=0", "198=3739:20130321:50018:5", "223=0.0425", "228=1", "236=0.0291371041", "238=0", "381=2432874.5", "423=1", "470=GB", "541=20360307", // NoPartyIDs "453=6", "448=VCON", "447=D", "452=1", "802=1", "523=14", "803=4", "448=TFOLIO:6804469", "447=D", "452=12", "448=TFOLIO", "447=D", "452=11", "448=THINKFOLIO LTD", "447=D", "452=13", "448=SXT", "447=D", "452=16", "448=TFOLIO:6804469", "447=D", "452=36", "10=152" }; string msgStr = String.Join(Message.SOH, msgFields) + Message.SOH; QuickFix.FIX44.ExecutionReport msg = new QuickFix.FIX44.ExecutionReport(); msg.FromString(msgStr, true, dd, dd, null); // <-- null factory! var expectedArr = new List <string>(); expectedArr.Add("<message>"); expectedArr.Add("<header>"); expectedArr.Add(@"<field number=""8""><![CDATA[FIX.4.4]]></field><field number=""9""><![CDATA[638]]></field><field number=""34""><![CDATA[360]]></field><field number=""35""><![CDATA[8]]></field><field number=""49""><![CDATA[BLPTSOX]]></field><field number=""52""><![CDATA[20130321-15:21:23]]></field><field number=""56""><![CDATA[THINKTSOX]]></field><field number=""57""><![CDATA[6804469]]></field><field number=""128""><![CDATA[ZERO]]></field>"); expectedArr.Add("</header>"); expectedArr.Add("<body>"); expectedArr.Add(@"<field number=""6""><![CDATA[122.255]]></field><field number=""11""><![CDATA[61101189]]></field><field number=""14""><![CDATA[1990000]]></field><field number=""15""><![CDATA[GBP]]></field><field number=""17""><![CDATA[VCON:20130321:50018:5:12]]></field><field number=""22""><![CDATA[4]]></field><field number=""31""><![CDATA[122.255]]></field><field number=""32""><![CDATA[1990000]]></field><field number=""37""><![CDATA[116]]></field><field number=""38""><![CDATA[1990000]]></field><field number=""39""><![CDATA[2]]></field><field number=""48""><![CDATA[GB0032452392]]></field><field number=""54""><![CDATA[1]]></field><field number=""55""><![CDATA[[N/A]]]></field><field number=""60""><![CDATA[20130321-15:21:23]]></field><field number=""64""><![CDATA[20130322]]></field><field number=""75""><![CDATA[20130321]]></field><field number=""106""><![CDATA[UK TSY 4 1/4% 2036]]></field><field number=""118""><![CDATA[2436321.85]]></field><field number=""150""><![CDATA[F]]></field><field number=""151""><![CDATA[0]]></field><field number=""157""><![CDATA[15]]></field><field number=""159""><![CDATA[3447.35]]></field><field number=""192""><![CDATA[0]]></field><field number=""198""><![CDATA[3739:20130321:50018:5]]></field><field number=""223""><![CDATA[0.0425]]></field><field number=""228""><![CDATA[1]]></field><field number=""236""><![CDATA[0.0291371041]]></field><field number=""238""><![CDATA[0]]></field><field number=""381""><![CDATA[2432874.5]]></field><field number=""423""><![CDATA[1]]></field><field number=""453""><![CDATA[6]]></field><field number=""470""><![CDATA[GB]]></field><field number=""541""><![CDATA[20360307]]></field><group><field number=""447""><![CDATA[D]]></field><field number=""448""><![CDATA[VCON]]></field><field number=""452""><![CDATA[1]]></field><field number=""802""><![CDATA[1]]></field><group><field number=""523""><![CDATA[14]]></field><field number=""803""><![CDATA[4]]></field></group></group><group><field number=""447""><![CDATA[D]]></field><field number=""448""><![CDATA[TFOLIO:6804469]]></field><field number=""452""><![CDATA[12]]></field></group><group><field number=""447""><![CDATA[D]]></field><field number=""448""><![CDATA[TFOLIO]]></field><field number=""452""><![CDATA[11]]></field></group><group><field number=""447""><![CDATA[D]]></field><field number=""448""><![CDATA[THINKFOLIO LTD]]></field><field number=""452""><![CDATA[13]]></field></group><group><field number=""447""><![CDATA[D]]></field><field number=""448""><![CDATA[SXT]]></field><field number=""452""><![CDATA[16]]></field></group><group><field number=""447""><![CDATA[D]]></field><field number=""448""><![CDATA[TFOLIO:6804469]]></field><field number=""452""><![CDATA[36]]></field></group>"); expectedArr.Add("</body>"); expectedArr.Add("<trailer>"); expectedArr.Add(@"<field number=""10""><![CDATA[152]]></field>"); expectedArr.Add("</trailer>"); expectedArr.Add("</message>"); expectedArr.Add(""); var expected = string.Join(Environment.NewLine, expectedArr); Assert.AreEqual(expected, msg.ToXML()); }
////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// #region "FIX42 Conversions to Fix44" /* * public static QuickFix.FIX44.SequenceReset Fix42SR_2_Fix44SR(QuickFix.FIX42.SequenceReset sr42) * { * try * { * QuickFix.FIX44.SequenceReset sr44 = new QuickFix.FIX44.SequenceReset(); * _fix42Header_2_Fix44Header(sr42.Header, sr44.Header); * * if (sr42.IsSetNewSeqNo()) sr44.Set(new NewSeqNo(sr42.NewSeqNo.getValue())); * if (sr42.IsSetGapFillFlag()) sr44.Set(new GapFillFlag(sr42.GapFillFlag.getValue())); * return sr44; * } * catch (Exception ex) * { * logger.Error("Fix42SR_2_Fix44SR(): Problemas na conversao da mensagem SR: " + ex.Message, ex); * return null; * } * } */ public static void Generate44RejectMessage(QuickFix.Message msg, SessionID s, string msgType, Exception ex, SessionAcceptor ssAcceptor, string msgText) { try { if (null != ex) { string aux = string.Format("QuickFix44 MsgType: [{0}], Message: [{1}]", msgType, ex.Message); logger.Error(aux, ex); } QuickFix.FIX44.Reject rej = new QuickFix.FIX44.Reject(); rej.Set(new RefMsgType(msgType)); rej.Set(new RefSeqNum(msg.Header.GetInt(Tags.MsgSeqNum))); if (string.IsNullOrEmpty(msgText)) { rej.Set(new Text("System unavaliable")); // Mensagem generica para nao expor possiveis erros de aplicacao } else { rej.Set(new Text(msgText)); } if (msgType.Equals(MsgType.ORDER_CANCEL_REQUEST) || msgType.Equals(MsgType.ORDER_CANCEL_REPLACE_REQUEST)) { QuickFix.FIX44.OrderCancelReject ocr = Fix44Translator.Fix44Reject2OrderCancelReject(rej, msg); Session.SendToTarget(ocr, s); if (null != ssAcceptor) { ssAcceptor.Send2DropCopy(ocr); } } else { QuickFix.FIX44.ExecutionReport er = Fix44Translator.Fix44Rejection2ExecutionReport(rej, msg); Session.SendToTarget(er, s); if (null != ssAcceptor) { ssAcceptor.Send2DropCopy(er); } } } catch (Exception exC) { logger.Error("Problemas na geracao de mensagem de reject (tratamento de excecoes) de mensagem fix 4.2: " + exC.Message, exC); } }
public void OnMessage(QuickFix.FIX44.NewOrderSingle ord, SessionID sessionID) { Symbol symbol = ord.Symbol; Side side = ord.Side; OrdType ordType = ord.OrdType; OrderQty orderQty = ord.OrderQty; Price price = new Price(10); //q isso? ClOrdID clOrdID = ord.ClOrdID; QuickFix.FIX44.ExecutionReport exReport = new QuickFix.FIX44.ExecutionReport( new OrderID(GenOrderID()), new ExecID(GenExecID()), new ExecType(ExecType.FILL), new OrdStatus(OrdStatus.FILLED), symbol, side, new LeavesQty(0), new CumQty(orderQty.getValue()), new AvgPx(price.getValue()) ); exReport.ClOrdID = clOrdID; exReport.Symbol = symbol; exReport.OrderQty = orderQty; exReport.LastQty = new LastQty(orderQty.getValue()); exReport.LastPx = new LastPx(price.getValue()); if (ord.IsSetAccount()) { exReport.Account = ord.Account; } try { Session.SendToTarget(exReport, sessionID); } catch (SessionNotFound ex) { Console.WriteLine("==session not found exception!=="); Console.WriteLine(ex.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void MessageHasDecimalWithNoLeadingZero() { // issue 160 var dd = new QuickFix.DataDictionary.DataDictionary(); dd.Load("../../../spec/fix/FIX44.xml"); string[] msgFields = { "8=FIX.4.4", "9=122", "35=8", "34=2", "49=sender", "52=20121024-12:21:42.170", "56=target", "37=orderid", "17=execid", "150=0", "39=0", "55=ibm", "228=.23", // Instrument component; 228 is a float type in the spec "54=1", "151=1", "14=1", "6=1", "10=45" }; string msgStr = String.Join(Message.SOH, msgFields) + Message.SOH; QuickFix.FIX44.ExecutionReport msg = new QuickFix.FIX44.ExecutionReport(); msg.FromString(msgStr, true, dd, dd, _defaultMsgFactory); Assert.AreEqual(0.23, msg.Factor.getValue()); }
private void timer3_Tick(object sender, EventArgs e) { QuickFix.FIX44.ExecutionReport[] trades = new QuickFix.FIX44.ExecutionReport[application.trades.Count]; application.trades.CopyTo(trades); int count = 0; foreach (QuickFix.FIX44.ExecutionReport trade in trades) { dOrderTable.Rows.Add(); dOrderTable.Rows[count].Cells[0].Value = trade.Header.GetDateTime(52).ToString(); dOrderTable.Rows[count].Cells[1].Value = trade.Symbol.ToString(); dOrderTable.Rows[count].Cells[2].Value = trade.Price.getValue().ToString(); dOrderTable.Rows[count].Cells[3].Value = trade.CumQty.getValue().ToString(); dOrderTable.Rows[count++].Cells[4].Value = (trade.Side.getValue() == '1')? "Buy":"Sell"; } if (count > 0) { dOrderTable.RowCount = count; } }
public void NestedRepeatingGroupParseGroupTest() { String data = "8=FIX.4.4\x01" + "9=309\x01" + "35=8\x01" + "49=ASX\x01" + "56=CL1_FIX44\x01" + "34=4\x01" + "52=20060324-01:05:58\x01" + "" + "17=X-B-WOW-1494E9A0:58BD3F9D-1109\x01" + "150=D\x01" + "39=0\x01" + "11=184271\x01" + "38=200\x01" + "198=1494E9A0:58BD3F9D\x01" + "" + "526=4324\x01" + "37=B-WOW-1494E9A0:58BD3F9D\x01" + "55=WOW\x01" + "54=1\x01" + "151=200\x01" + "14=0\x01" + "40=2\x01" + "44=15\x01" + "59=1\x01" + "6=0\x01" + "" + "453=3\x01" + "448=AAA35791\x01" + "447=D\x01" + "452=3\x01" + "802=1\x01" + "523=OHAI123\x01" + "448=8\x01" + "447=D\x01" + "452=4\x01" + "448=FIX11\x01" + "447=D\x01" + "452=36\x01" + "" + "60=20060320-03:34:29\x01" + "10=169\x01" + ""; var msg = new QuickFix.FIX44.ExecutionReport(); var dd = new QuickFix.DataDictionary.DataDictionary(); dd.Load("../../../spec/fix/FIX44.xml"); msg.FromString(data, false, dd, dd, _defaultMsgFactory); var subGrp = msg.GetGroup(1, Tags.NoPartyIDs).GetGroup(1, Tags.NoPartySubIDs); Assert.That(subGrp.GetString(Tags.PartySubID), Is.EqualTo("OHAI123")); }
public void OnMessage(QuickFix.FIX44.ExecutionReport m, SessionID s) { FillModel fill = new FillModel { AvgPx = m.Price.getValue(), ClOrderId = m.ClOrdID.getValue(), CumQty = (int)m.CumQty.getValue(), LastQty = (int)m.LastQty.getValue(), LeavesQty = (int)m.LeavesQty.getValue(), OrderQty = (int)m.OrderQty.getValue(), Side = m.Side.getValue(), OrdStatus = m.OrdStatus.getValue(), TickerSymbol = m.Symbol.getValue(), ExecId = m.ExecID.getValue(), ExecType = m.ExecType.getValue() - '0', OrderId = m.OrderID.getValue(), }; FillReceived?.Invoke(this, fill); }
public void HandleExecutionReport(QuickFix.FIX44.ExecutionReport msg) { try { string clOrdId = msg.ClOrdID.Obj; string status = FixEnumTranslator.Translate(msg.OrdStatus); Trace.WriteLine("OVM: Handling ExecutionReport: " + clOrdId + " / " + status); lock (_ordersLock) { foreach (OrderRecord r in Orders) { if (r.ClOrdID == clOrdId) { r.Status = status; if (msg.IsSetLastPx()) { r.Price = msg.LastPx.Obj; } if (msg.IsSetOrderID()) { r.OrderID = msg.OrderID.Obj; } r.LeavesQty = msg.LeavesQty.getValue(); r.TotalFilledQty = msg.CumQty.getValue(); r.LastQty = msg.LastQty.getValue(); return; } } } Trace.WriteLine("OVM: No order corresponds to ClOrdID '" + clOrdId + "'"); } catch (Exception e) { Trace.WriteLine(e.ToString()); } }
public OrderRecord(QuickFix.FIX44.ExecutionReport msg) { // If creating from an ExecutionReport then it's from an incoming message // and therefore we shouldn't need the NOS details that don't exist anyway OriginalNos = null; ClOrdID = msg.ClOrdID.Obj; OrderID = msg.OrderID.Obj; Symbol = msg.Symbol.Obj; Side = Services.TranslateFixFields.Translate(msg.Side); //OrdType = FIXApplication.FixEnumTranslator.Translate(msg.OrdType); OrdType = OrderType.Limit; // Not specified in ExecutionReport //Price = msg.Price.Obj; // Not specified in ExecutionReport Price = msg.AvgPx.Obj; // TODO We may need to be smarter, updates should use LastPx but what about new orders? Quantity = msg.LeavesQty.Obj; Status = Services.TranslateFixFields.Translate(msg.OrdStatus); if (Status == OrderStatus.Rejected && msg.IsSetOrdRejReason()) { RejectReason = msg.OrdRejReason.ToString(); } }
public void OnMessage(QuickFix.FIX44.Quote quote, SessionID s) { try { Console.WriteLine("Received Quote Message."); QuickFix.FIX44.ExecutionReport exec = new QuickFix.FIX44.ExecutionReport(); exec.SetField(new OrderID(quote.QuoteID.getValue())); exec.SetField(new ClOrdID(quote.QuoteReqID.getValue())); exec.SetField(new Side(quote.Side.getValue())); exec.SetField(new Symbol(quote.Symbol.getValue())); exec.SetField(new Currency(quote.Currency.getValue())); exec.SetField(new SecurityType(quote.SecurityType.getValue())); exec.SetField(new CFICode(quote.CFICode.getValue())); if (quote.BidPx.getValue() > 0) { exec.SetField(new Price(quote.OfferPx.getValue())); } else { exec.SetField(new Price(quote.BidPx.getValue())); } exec.SetField(new OrderQty(quote.OrderQty.getValue())); exec.SetField(new TransactTime(DateTime.Now.Date)); exec.SetField(new SettlDate(quote.SettlDate.getValue())); exec.SetField(new Account(quote.Account.getValue())); _session.Send(exec); Console.WriteLine(exec.ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void FromString_Groups_NoFactory() { // issue 179 var dd = new QuickFix.DataDictionary.DataDictionary(); dd.Load("../../../spec/fix/FIX44.xml"); string[] msgFields = { // header "8=FIX.4.4", "9=638", "35=8", "34=360", "49=BLPTSOX", "52=20130321-15:21:23", "56=THINKTSOX", "57=6804469", "128=ZERO", // non-group body fields "6=122.255", "11=61101189", "14=1990000", "15=GBP", "17=VCON:20130321:50018:5:12", "22=4", "31=122.255", "32=1990000", "37=116", "38=1990000", "39=2", "48=GB0032452392", "54=1", "55=[N/A]", "60=20130321-15:21:23", "64=20130322", "75=20130321", "106=UK TSY 4 1/4% 2036", "118=2436321.85", "150=F", "151=0", "157=15", "159=3447.35", "192=0", "198=3739:20130321:50018:5", "223=0.0425", "228=1", "236=0.0291371041", "238=0", "381=2432874.5", "423=1", "470=GB", "541=20360307", // NoPartyIDs "453=6", "448=VCON", "447=D", "452=1", "802=1", "523=14", "803=4", "448=TFOLIO:6804469", "447=D", "452=12", "448=TFOLIO", "447=D", "452=11", "448=THINKFOLIO LTD", "447=D", "452=13", "448=SXT", "447=D", "452=16", "448=TFOLIO:6804469", "447=D", "452=36", "10=152" }; string msgStr = String.Join(Message.SOH, msgFields) + Message.SOH; QuickFix.FIX44.ExecutionReport msg = new QuickFix.FIX44.ExecutionReport(); msg.FromString(msgStr, true, dd, dd, null); // <-- null factory! Console.WriteLine(msg.ToString()); QuickFix.FIX44.ExecutionReport.NoPartyIDsGroup partyGroup = new QuickFix.FIX44.ExecutionReport.NoPartyIDsGroup(); msg.GetGroup(2, partyGroup); Assert.False(partyGroup.IsSetNoPartySubIDs()); }
public void calculateProfit(QuickFix.FIX44.ExecutionReport order) { try { if (order.Side.getValue() == '1') { buyingPrices.Add(askPrices.Count, (double)order.Price.getValue()); } else if (order.Side.getValue() == '2') { sellingPrices.Add(askPrices.Count, (double)order.Price.getValue()); } } catch (Exception e) { logger.Error(e.Message); logger.Error(e.StackTrace); } if (order.Side.getValue() == '1') { portfolioValue -= (order.Price.getValue() + brokerage) * order.CumQty.getValue(); totalOrders += (long)order.CumQty.getValue(); } else if (order.Side.getValue() == '2') { portfolioValue += (order.Price.getValue() - brokerage) * order.CumQty.getValue(); totalOrders -= (long)order.CumQty.getValue(); } if (totalOrders < 0) { profit = portfolioValue + (Convert.ToDecimal(askPrices[askPrices.Count - 1]) + brokerage) * totalOrders; } else if (totalOrders > 0) { profit = portfolioValue + (Convert.ToDecimal(bidPrices[bidPrices.Count - 1]) - brokerage) * totalOrders; } }
public void OrderUpdate() { UnitTestContext context = new UnitTestContext(); context.Login(); OrderViewModel vm = new OrderViewModel(context.App, new FIXApplication.NullFixStrategy()); // send an order with default arguments vm.SendBuyCommand.Execute(null); Assert.AreEqual(1, context.Session.MsgLookup[QuickFix.FIX44.NewOrderSingle.MsgType].Count); QuickFix.FIX44.NewOrderSingle msg = context.Session.MsgLookup[QuickFix.FIX44.NewOrderSingle.MsgType][0] as QuickFix.FIX44.NewOrderSingle; // verify grid content (redundant with earlier tests, but whatever) Assert.AreEqual(1, vm.Orders.Count); OrderRecord or = vm.Orders.First(); Assert.AreEqual("IBM", or.Symbol); Assert.AreEqual(-1, or.Price); Assert.AreEqual("Market", or.OrdType); Assert.AreEqual("Buy", or.Side); Assert.AreEqual("New", or.Status); // send an execution report that will update the grid QuickFix.FIX44.ExecutionReport r = CreateExReport( or.ClOrdID, "foo", QuickFix.Fields.ExecTransType.NEW, QuickFix.Fields.ExecType.FILL, QuickFix.Fields.OrdStatus.FILLED, "IBM", QuickFix.Fields.Side.BUY, 0, 0, 0); r.LastPx = new QuickFix.Fields.LastPx(999m); r.ClOrdID = new QuickFix.Fields.ClOrdID(msg.ClOrdID.Obj); context.App.FromApp(r, context.Session.SessionID); // check that it got changed Assert.AreEqual(1, vm.Orders.Count); Assert.AreEqual(999, or.Price); Assert.AreEqual("Filled", or.Status); }
private void SendExecution(SessionID s, char ordStatus, char execType, QuickFix.FIX44.NewOrderSingle n, decimal leavesQty, decimal cumQty, decimal avgPx, decimal lastQty, decimal lastPrice) { QuickFix.FIX44.ExecutionReport exReport = new QuickFix.FIX44.ExecutionReport( new OrderID(GenOrderID()), new ExecID(GenExecID()), new ExecType(execType), new OrdStatus(ordStatus), n.Symbol, //shouldn't be here? n.Side, new LeavesQty(leavesQty), new CumQty(cumQty), new AvgPx(avgPx)); exReport.ClOrdID = new ClOrdID(n.ClOrdID.getValue()); exReport.Set(new LastQty(lastQty)); exReport.Set(new LastPx(lastPrice)); if (n.IsSetAccount()) { exReport.SetField(n.Account); } try { Session.SendToTarget(exReport, s); } catch (SessionNotFound ex) { Console.WriteLine("==session not found exception!=="); Console.WriteLine(ex.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void ManyExecutions() { UnitTestContext context = new UnitTestContext(); context.Login(); ExecutionViewModel vm = new ExecutionViewModel(context.App); QuickFix.FIX44.ExecutionReport ex1 = CreateExReport("order1", "exec1", QuickFix.Fields.ExecTransType.NEW, QuickFix.Fields.ExecType.NEW, QuickFix.Fields.OrdStatus.NEW, "IBM", QuickFix.Fields.Side.BUY, 1.23m, 4.56m, 7.89m); QuickFix.FIX44.ExecutionReport ex2 = CreateExReport("order1", "exec1", QuickFix.Fields.ExecTransType.CORRECT, QuickFix.Fields.ExecType.NEW, QuickFix.Fields.OrdStatus.NEW, "ABC", QuickFix.Fields.Side.SELL, 1.23m, 4.56m, 7.89m); QuickFix.FIX44.ExecutionReport ex3 = CreateExReport("order1", "exec1", QuickFix.Fields.ExecTransType.CANCEL, QuickFix.Fields.ExecType.NEW, QuickFix.Fields.OrdStatus.NEW, "XYZ", QuickFix.Fields.Side.BUY, 1.23m, 4.56m, 7.89m); context.App.FromApp(ex1, context.Session.SessionID); context.App.FromApp(ex2, context.Session.SessionID); context.App.FromApp(ex3, context.Session.SessionID); Assert.AreEqual(3, vm.Executions.Count); Assert.AreEqual("order1", vm.Executions[0].OrderID); Assert.AreEqual("New", vm.Executions[0].ExecTransType); Assert.AreEqual("IBM", vm.Executions[0].Symbol); Assert.AreEqual("Buy", vm.Executions[0].Side); Assert.AreEqual("order1", vm.Executions[1].OrderID); Assert.AreEqual("Correct", vm.Executions[1].ExecTransType); Assert.AreEqual("ABC", vm.Executions[1].Symbol); Assert.AreEqual("Sell", vm.Executions[1].Side); Assert.AreEqual("order1", vm.Executions[2].OrderID); Assert.AreEqual("Cancel", vm.Executions[2].ExecTransType); Assert.AreEqual("XYZ", vm.Executions[2].Symbol); Assert.AreEqual("Buy", vm.Executions[2].Side); }
public void OnMessage(QuickFix.FIX44.ExecutionReport m, SessionID s) { Console.WriteLine("Received execution report"); }
public void OnMessage(QuickFix.FIX44.ExecutionReport m, SessionID s) { Logger.Instance().Log($"REPLY (ExecutionReport) => {m.ToString()}"); }
public void OnMessage(QuickFix.FIX44.ExecutionReport msg, SessionID sessionID) { }
public static QuickFix.FIX44.ExecutionReport Fix44Rejection2ExecutionReport(QuickFix.Message msgReject, QuickFix.Message msgOri) { try { QuickFix.FIX44.ExecutionReport er = new QuickFix.FIX44.ExecutionReport(); if (msgOri.IsSetField(Tags.OrderID)) { er.Set(new OrderID(msgOri.GetString(Tags.OrderID))); } else { er.Set(new OrderID("NONE")); } if (msgOri.IsSetField(Tags.ClOrdID)) { er.Set(new ClOrdID(msgOri.GetField(Tags.ClOrdID))); } if (msgOri.IsSetField(Tags.OrigClOrdID)) { er.Set(new OrigClOrdID(msgOri.GetField(Tags.OrigClOrdID))); } // Fazer atribuicao dos PartyIDs da mensagem original int len = msgOri.GetInt(Tags.NoPartyIDs); for (int i = 0; i < len; i++) { Group grp = msgOri.GetGroup(i + 1, Tags.NoPartyIDs); er.AddGroup(grp); } er.Set(new ExecID(DateTime.Now.ToString("yyyyMMddHHmmssfff"))); er.Set(new ExecType(ExecType.REJECTED)); er.Set(new OrdStatus(OrdStatus.REJECTED)); if (msgOri.IsSetField(Tags.Account)) { er.Set(new Account(msgOri.GetField(Tags.Account))); } er.Set(new Symbol(msgOri.GetField(Tags.Symbol))); if (msgOri.IsSetField(Tags.SecurityID)) { er.Set(new SecurityID(msgOri.GetField(Tags.SecurityID))); } if (msgOri.IsSetField(Tags.SecurityIDSource)) { er.Set(new SecurityIDSource(msgOri.GetField(Tags.SecurityIDSource))); } er.Set(new Side(msgOri.GetChar(Tags.Side))); er.Set(new OrderQty(msgOri.GetDecimal(Tags.OrderQty))); if (msgOri.IsSetField(Tags.OrdType)) { er.Set(new OrdType(msgOri.GetChar(Tags.OrdType))); } if (msgOri.IsSetField(Tags.Price)) { er.Set(new Price(msgOri.GetDecimal(Tags.Price))); } if (msgOri.IsSetField(Tags.StopPx)) { er.Set(new StopPx(msgOri.GetDecimal(Tags.StopPx))); } if (msgOri.IsSetField(Tags.TimeInForce)) { er.Set(new TimeInForce(msgOri.GetChar(Tags.TimeInForce))); } if (msgOri.IsSetField(Tags.ExpireDate)) { er.Set(new ExpireDate(msgOri.GetField(Tags.ExpireDate))); } er.Set(new LeavesQty(0)); er.Set(new CumQty(0)); er.Set(new AvgPx(Decimal.Zero)); DateTime transact = DateTime.UtcNow; er.Set(new TransactTime(transact)); if (msgOri.IsSetField(Tags.MaxFloor)) { er.Set(new MaxFloor(msgOri.GetDecimal(Tags.MaxFloor))); } if (msgOri.IsSetField(Tags.Memo)) { er.SetField(new Memo(msgOri.GetString(Tags.Memo))); } if (msgReject.IsSetField(Tags.Text)) { er.Set(new Text(msgReject.GetField(Tags.Text))); } if (msgReject.IsSetField(Tags.OrderID)) { er.Set(new OrderID(msgReject.GetField(Tags.OrderID))); } return(er); } catch (Exception ex) { logger.Error("Fix44Rejection2ExecutionReport(): " + ex.Message, ex); return(null); } }
public void OnMessage(QuickFix.FIX44.ExecutionReport m, SessionID s) { var utcNow = DateTime.UtcNow; var stringBuilder = new StringBuilder("***Execution report***:\r\n"); stringBuilder.Append("================\r\n"); for (int i = 1; i <= m.GetInt(QuickFix.Fields.Tags.NoContraBrokers); i++) { var group = new QuickFix.FIX44.ExecutionReport.NoContraBrokersGroup(); m.GetGroup(i, group); stringBuilder.Append("LP:").Append(group.ContraBroker.getValue()).Append("\r\n"); } stringBuilder.Append("Price:").Append(m.AvgPx.getValue()).Append("\r\n"); stringBuilder.Append("Side:").Append(m.Side.getValue() == '1'?"Buy" :"Sell").Append("\r\n"); stringBuilder.Append("Quantity:").Append(m.OrderQty.getValue()).Append("\r\n"); var TimeIn = default(DateTime); var TimeOut = default(DateTime); var BrokerReceipt = default(DateTime); var BrokerExec = default(DateTime); for (int i = 1; i <= m.GetInt(QuickFix.Fields.Tags.NoTrdRegTimestamps); i++) { var group = new QuickFix.FIX44.CollateralReport.NoTrdRegTimestampsGroup(); m.GetGroup(i, group); switch (i) { case 1: TimeIn = group.TrdRegTimestamp.getValue(); break; case 2: TimeOut = group.TrdRegTimestamp.getValue(); break; case 3: BrokerReceipt = group.TrdRegTimestamp.getValue(); break; case 4: BrokerExec = group.TrdRegTimestamp.getValue(); break; } } var clientSentDate = this._orderClientTimestamp[m.ClOrdID.getValue()]; stringBuilder.Append("TimeStamps:\r\n"); stringBuilder.Append("Customer sent:").Append(clientSentDate.ToString("h:m:s.fff")).Append("\r\n"); stringBuilder.Append("Time in:").Append(TimeIn.ToString("h:m:s.fff")).Append("\r\n"); stringBuilder.Append("Broker receipt:").Append(BrokerReceipt.ToString("h:m:s.fff")).Append("\r\n"); stringBuilder.Append("Broker exec:").Append(BrokerExec.ToString("h:m:s.fff")).Append("\r\n"); stringBuilder.Append("Time out:").Append(TimeOut.ToString("h:m:s.fff")).Append("\r\n"); stringBuilder.Append("Customer exec:").Append(utcNow.ToString("h:m:s.fff")).Append("\r\n"); stringBuilder.Append("Customer | IdsRoot | LP\r\n").Append("\r\n"); stringBuilder.Append("Customer sent->| |\r\n").Append("\r\n"); stringBuilder.Append(" |-> Time in |\r\n").Append("\r\n"); stringBuilder.Append(" | |-> Broker Receipt\r\n").Append("\r\n"); stringBuilder.Append(" | |<- Broker exec\r\n").Append("\r\n"); stringBuilder.Append(" |<- Time out |\r\n").Append("\r\n"); stringBuilder.Append("Customer exec<-| |\r\n").Append("\r\n"); Console.WriteLine(stringBuilder.ToString()); }
public void FromString_Groups_NoFactory() { // issue 179 var dd = new QuickFix.DataDictionary.DataDictionary(); dd.Load("../../../spec/fix/FIX44.xml"); string[] msgFields = { // header "8=FIX.4.4","9=638", "35=8", "34=360", "49=BLPTSOX", "52=20130321-15:21:23", "56=THINKTSOX", "57=6804469", "128=ZERO", // non-group body fields "6=122.255", "11=61101189", "14=1990000", "15=GBP", "17=VCON:20130321:50018:5:12", "22=4", "31=122.255", "32=1990000", "37=116", "38=1990000", "39=2", "48=GB0032452392", "54=1", "55=[N/A]", "60=20130321-15:21:23", "64=20130322", "75=20130321", "106=UK TSY 4 1/4% 2036", "118=2436321.85", "150=F", "151=0", "157=15", "159=3447.35", "192=0", "198=3739:20130321:50018:5", "223=0.0425", "228=1", "236=0.0291371041", "238=0", "381=2432874.5", "423=1", "470=GB", "541=20360307", // NoPartyIDs "453=6", "448=VCON", "447=D", "452=1", "802=1", "523=14", "803=4", "448=TFOLIO:6804469", "447=D", "452=12", "448=TFOLIO", "447=D", "452=11", "448=THINKFOLIO LTD", "447=D", "452=13", "448=SXT", "447=D", "452=16", "448=TFOLIO:6804469", "447=D", "452=36", "10=152" }; string msgStr = String.Join(Message.SOH, msgFields) + Message.SOH; QuickFix.FIX44.ExecutionReport msg = new QuickFix.FIX44.ExecutionReport(); msg.FromString(msgStr, true, dd, dd, null); // <-- null factory! Console.WriteLine(msg.ToString()); QuickFix.FIX44.ExecutionReport.NoPartyIDsGroup partyGroup = new QuickFix.FIX44.ExecutionReport.NoPartyIDsGroup(); msg.GetGroup(2, partyGroup); Assert.False(partyGroup.IsSetNoPartySubIDs()); }
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 void ToXMLWithGroupsTest() { var dd = new QuickFix.DataDictionary.DataDictionary(); dd.Load("../../../spec/fix/FIX44.xml"); string[] msgFields = { // header "8=FIX.4.4","9=638", "35=8", "34=360", "49=BLPTSOX", "52=20130321-15:21:23", "56=THINKTSOX", "57=6804469", "128=ZERO", // non-group body fields "6=122.255", "11=61101189", "14=1990000", "15=GBP", "17=VCON:20130321:50018:5:12", "22=4", "31=122.255", "32=1990000", "37=116", "38=1990000", "39=2", "48=GB0032452392", "54=1", "55=[N/A]", "60=20130321-15:21:23", "64=20130322", "75=20130321", "106=UK TSY 4 1/4% 2036", "118=2436321.85", "150=F", "151=0", "157=15", "159=3447.35", "192=0", "198=3739:20130321:50018:5", "223=0.0425", "228=1", "236=0.0291371041", "238=0", "381=2432874.5", "423=1", "470=GB", "541=20360307", // NoPartyIDs "453=6", "448=VCON", "447=D", "452=1", "802=1", "523=14", "803=4", "448=TFOLIO:6804469", "447=D", "452=12", "448=TFOLIO", "447=D", "452=11", "448=THINKFOLIO LTD", "447=D", "452=13", "448=SXT", "447=D", "452=16", "448=TFOLIO:6804469", "447=D", "452=36", "10=152" }; string msgStr = String.Join(Message.SOH, msgFields) + Message.SOH; QuickFix.FIX44.ExecutionReport msg = new QuickFix.FIX44.ExecutionReport(); msg.FromString(msgStr, true, dd, dd, null); // <-- null factory! string xmlDoc = msg.toXML(); System.Diagnostics.Debug.Print(xmlDoc.ToString()); XDocument doc = null; try { doc = XDocument.Parse(xmlDoc); } catch (Exception e) { Assert.Fail("Badly formed XML generated: " + e.Message); } var groups = doc.Descendants("message").Descendants("body").Elements("group") .Select(group => new { numbers = group.Descendants("field").Attributes("number"), values = group.Descendants("field") }) .ToList(); int ct = 0; foreach (var elem in groups) { int number = 0; Group group = msg.GetGroup(++ct, 453); var valueEnum = elem.values.GetEnumerator(); foreach (var numberEnum in elem.numbers) { valueEnum.MoveNext(); string value = valueEnum.Current.Value; if (int.TryParse(numberEnum.Value.ToString(), out number) == false) { Assert.Fail("should be number " + numberEnum.Value.ToString()); } else { if (group.IsSetField(number)) { string msgValue = group.GetField(number); Assert.That(value, Is.EqualTo(msgValue)); } } } } }
/// <summary> /// Report after a request about orders is made /// Possible cause: /// - New order /// - Cancel order /// - Rejected order /// - Requested order info /// - Order filled or partially filled /// </summary> /// <param name="msg"></param> /// <param name="sessionID"></param> public void OnMessage(QuickFix.FIX44.ExecutionReport msg, SessionID sessionID) { char executionReportType = msg.GetChar(Tags.ExecType); int clientOrderID = msg.GetInt(Tags.ClOrdID); switch (executionReportType) { case ExecType.NEW: { // New order execution report string avgPrice = msg.GetString(Tags.AvgPx); char side = msg.GetChar(Tags.Side); var order = new Order() { OrderID = msg.GetString(Tags.ExecID), ClientOrderID = clientOrderID, Price = double.Parse(avgPrice), Side = side }; CurrentOrders.Add(order); OrderSubmitCallback?.Invoke(false); OrderSubmitCallback = null; Log.Write($"Submission confirmed {order}", 2); break; } case ExecType.PARTIAL_FILL: { // Order executed double executionPrice = (double)msg.GetDecimal(Tags.AvgPx); int orderStatus = msg.GetInt(Tags.OrdStatus); char side = msg.GetChar(Tags.Side); double remainingQty = (double)msg.GetDecimal(Tags.LeavesQty); var order = CurrentOrders.First(o => o.ClientOrderID == clientOrderID); order.FilledVolume = order.Volume - remainingQty; Log.Write($"Partial fill {order}", 2); break; } case ExecType.FILL: { // Order executed double executionPrice = (double)msg.GetDecimal(Tags.AvgPx); int orderStatus = msg.GetInt(Tags.OrdStatus); char side = msg.GetChar(Tags.Side); var order = CurrentOrders.First(o => o.ClientOrderID == clientOrderID); order.FilledVolume = order.Volume; //CurrentOrders.Remove(order); Log.Write($"Fill {order}", 2); break; } case ExecType.CANCELED: { // Order cancel report string orderID = msg.GetString(Tags.ExecID); CurrentOrders.RemoveAll(o => o.ClientOrderID == clientOrderID); OrderCancelCallback?.Invoke(false); OrderCancelCallback = null; break; } case ExecType.REJECTED: { // Rejected order execution report OrderSubmitCallback?.Invoke(true); OrderSubmitCallback = null; string orderStatus = msg.GetString(Tags.OrdStatus); string text = msg.GetString(Tags.Text); Log.Write($"Order rejected | status: {orderStatus} | reason: {text}", 1); break; } case ExecType.PENDING_NEW: { // Requested Order info int numReports = msg.GetInt(Tags.TotNumReports); if (!CurrentOrders.Exists(o => o.ClientOrderID.Equals(clientOrderID))) { CurrentOrders.Add(new Order() { OrderID = msg.GetString(Tags.OrderID), ClientOrderID = clientOrderID, Price = (double)msg.GetDecimal(Tags.AvgPx), Side = msg.GetChar(Tags.Side) }); } break; } default: Log.Write($"Unknown execution report type {executionReportType}", 0); break; } }
public static List <QuickFix.FIX44.ExecutionReport> Fix44Rejection2ExecutionReportNOC(QuickFix.Message msgReject, QuickFix.FIX44.NewOrderCross noc) { try { QuickFix.FIX44.ExecutionReport er1 = new QuickFix.FIX44.ExecutionReport(); QuickFix.FIX44.ExecutionReport er2 = new QuickFix.FIX44.ExecutionReport(); er1.Set(new OrderID("NONE")); er2.Set(new OrderID("NONE")); if (noc.IsSetNoSides() && noc.NoSides.getValue() == 2) { QuickFix.Group grpNoSides = noc.GetGroup(1, Tags.NoSides); if (grpNoSides.IsSetField(Tags.ClOrdID)) { er1.Set(new ClOrdID(grpNoSides.GetField(Tags.ClOrdID))); } er1.Set(new ExecID(DateTime.Now.ToString("yyyyMMddHHmmssfff"))); er1.Set(new ExecType(ExecType.REJECTED)); er1.Set(new OrdStatus(OrdStatus.REJECTED)); if (grpNoSides.IsSetField(Tags.Account)) { er1.Set(new Account(grpNoSides.GetField(Tags.Account))); } er1.Set(new Symbol(noc.GetField(Tags.Symbol))); if (noc.IsSetField(Tags.SecurityID)) { er1.Set(new SecurityID(noc.GetField(Tags.SecurityID))); } if (noc.IsSetField(Tags.SecurityIDSource)) { er1.Set(new SecurityIDSource(noc.GetField(Tags.SecurityIDSource))); } er1.Set(new Side(grpNoSides.GetChar(Tags.Side))); er1.Set(new OrderQty(grpNoSides.GetDecimal(Tags.OrderQty))); if (noc.IsSetField(Tags.OrdType)) { er1.Set(new OrdType(noc.GetChar(Tags.OrdType))); } if (noc.IsSetField(Tags.Price)) { er1.Set(new Price(noc.GetDecimal(Tags.Price))); } er1.Set(new LeavesQty(0)); er1.Set(new CumQty(0)); er1.Set(new AvgPx(Decimal.Zero)); DateTime transact1 = DateTime.UtcNow; er1.Set(new TransactTime(transact1)); if (msgReject.IsSetField(Tags.Text)) { er1.Set(new Text(msgReject.GetField(Tags.Text))); } grpNoSides = noc.GetGroup(2, Tags.NoSides); if (grpNoSides.IsSetField(Tags.ClOrdID)) { er2.Set(new ClOrdID(grpNoSides.GetField(Tags.ClOrdID))); } er2.Set(new ExecID(DateTime.Now.ToString("yyyyMMddHHmmssfff"))); er2.Set(new ExecType(ExecType.REJECTED)); er2.Set(new OrdStatus(OrdStatus.REJECTED)); if (grpNoSides.IsSetField(Tags.Account)) { er2.Set(new Account(grpNoSides.GetField(Tags.Account))); } er2.Set(new Symbol(noc.GetField(Tags.Symbol))); if (noc.IsSetField(Tags.SecurityID)) { er2.Set(new SecurityID(noc.GetField(Tags.SecurityID))); } if (noc.IsSetField(Tags.SecurityIDSource)) { er2.Set(new SecurityIDSource(noc.GetField(Tags.SecurityIDSource))); } er2.Set(new Side(grpNoSides.GetChar(Tags.Side))); er2.Set(new OrderQty(grpNoSides.GetDecimal(Tags.OrderQty))); if (noc.IsSetField(Tags.OrdType)) { er2.Set(new OrdType(noc.GetChar(Tags.OrdType))); } if (noc.IsSetField(Tags.Price)) { er2.Set(new Price(noc.GetDecimal(Tags.Price))); } er2.Set(new LeavesQty(0)); er2.Set(new CumQty(0)); er2.Set(new AvgPx(Decimal.Zero)); DateTime transact2 = DateTime.UtcNow; er2.Set(new TransactTime(transact2)); if (msgReject.IsSetField(Tags.Text)) { er2.Set(new Text(msgReject.GetField(Tags.Text))); } } List <QuickFix.FIX44.ExecutionReport> ret = new List <QuickFix.FIX44.ExecutionReport>(); ret.Add(er1); ret.Add(er2); return(ret); } catch (Exception ex) { logger.Error("Fix44Rejection2ExecutionReportNOC(): " + ex.Message, ex); return(null); } }
private void OmsFixClient_OnExecutionReport(object sender, QuickFix.FIX44.ExecutionReport e) { Console.WriteLine("EXECUTION REPORT " + e); }
public void OnMessage(QuickFix.FIX44.ExecutionReport n, SessionID s) { OnExecutionReport?.Invoke(this, n); }
public void TestQuickFIXCompatibleGroups() { // allow QuickFIX compatible group parsing (note test MissingDelimiterField proves the reverse) var dd = new QuickFix.DataDictionary.DataDictionary(); dd.Load("../../../spec/fix/FIX44.xml"); // group 555 does not begin with 600 string[] msgFields = { "8=FIX.4.4", "9=296", "35=8", "34=2", "49=XXXXX", "52=20150731-12:00:00.000", "56=CLIENT2", "1=C", "11=T01", "17=123", "37=ST1", "39=0", "44=10000", "54=1", "55=CAD", "60=20150731-12:00:00.000", "75=20150731", "109=BRK","150=0","167=F", "375=ABC", "423=0","555=1", "687=1","943=R1", "5296=1", "5322=ABC","5442=MST1", "5444=1", "5474=S", "5475=MAR16", "5476=PRIV1", "5477=PUB1", "5478=0","5479=0","5681=0","7931=0","10=43" }; string msgStr = String.Join(Message.SOH, msgFields) + Message.SOH; QuickFix.FIX44.ExecutionReport msg = new QuickFix.FIX44.ExecutionReport(); msg.QuickFIXCompatibleGroups = true; Assert.DoesNotThrow(delegate { msg.FromString(msgStr, true, dd, dd, _defaultMsgFactory); }); Group group = msg.GetGroup(1, 555); Assert.IsNotNull(group, "Group should be created"); }
private void _processMessage(TOMessage to) { try { if (null != to) { QuickFix.Message msgQF = to.MensagemQF; string msgType = msgQF.Header.GetField(Tags.MsgType); int account = 0; string strAcc = string.Empty; #region Limit Validation // Atualizacao dos valores de limite, de acordo com o execution report if (this.CalcularLimite) { if (this.Config.Bolsa.Equals(ExchangePrefixes.BOVESPA, StringComparison.InvariantCultureIgnoreCase)) { strAcc = msgQF.IsSetField(Tags.Account) ? msgQF.GetField(Tags.Account) : string.Empty; if (!string.IsNullOrEmpty(strAcc)) { account = Convert.ToInt32(strAcc.Remove(strAcc.Length - 1)); } else { account = 0; } } else { strAcc = msgQF.IsSetField(Tags.Account) ? msgQF.GetField(Tags.Account) : string.Empty; if (!string.IsNullOrEmpty(strAcc)) { account = Convert.ToInt32(strAcc); } else { account = 0; } } bool bProfileInst = false; LimitResponse retProfile = LimiteManager.LimitControl.GetInstance().VerifyInstitutionalProfile(account); if (0 != retProfile.ErrorCode) { bProfileInst = true; } if (msgType == MsgType.EXECUTION_REPORT && !bProfileInst) { // Validar o perfil instituicional QuickFix.FIX44.ExecutionReport er = (QuickFix.FIX44.ExecutionReport)msgQF; // Bovespa if (this.Config.Bolsa.Equals(ExchangePrefixes.BOVESPA, StringComparison.InvariantCultureIgnoreCase)) { // BOVESPA decimal ultimoPreco = StreamerManager.GetInstance().GetLastPrice(er.Symbol.ToString()); if (Decimal.Zero != ultimoPreco) { LimitResponse ret = new LimitResponse(); decimal valorAlocado = er.OrderQty.getValue() * ultimoPreco; // Retirar o digito verificador string chaveAtual = er.ClOrdID.ToString() + "-" + strAcc + "-" + er.Symbol.ToString(); switch (er.OrdStatus.getValue()) { // Alocar limite da parte e contra parte case OrdStatus.NEW: case OrdStatus.REPLACED: case OrdStatus.CANCELED: { // Buscar o "new order" referencial para busca do TipoLimite // toOrder = this.Initiator.GetTOOrderSession(chaveAtual); if (null == to.Order) { logger.Info("RefOrder não encontrada (New): " + chaveAtual); } else { ret = LimiteManager.LimitControl.GetInstance().UpdateOperationalLimitBovespa(account, to.TipoLimite, valorAlocado, ultimoPreco, Convert.ToInt32(er.Side.ToString()), er.OrdStatus.getValue()); if (0 != ret.ErrorCode) { logger.Info("Erro na atualizacao do limite operacional Bovespa (New): " + ret.ErrorMessage); } } } break; // Atualizar a quantidade executada case OrdStatus.FILLED: case OrdStatus.PARTIALLY_FILLED: if (null != to.Order) { to.Order.CumQty = Convert.ToInt32(er.CumQty.getValue()); valorAlocado = er.CumQty.getValue() * ultimoPreco; ret = LimiteManager.LimitControl.GetInstance().UpdateOperationalLimitBovespa(account, to.TipoLimite, valorAlocado, ultimoPreco, Convert.ToInt32(er.Side.ToString()), er.OrdStatus.getValue()); if (0 != ret.ErrorCode) { logger.Info("Erro na atualizacao do limite operacional Bovespa (Filled / Partially Filled): " + ret.ErrorMessage); } } else { logger.Info("RefOrder não encontrada (New): " + chaveAtual); } break; } } else { string symbol = er.IsSetSymbol() ? er.Symbol.getValue() : string.Empty; logger.Info("Preco base (ultimo preco) zerado, ignorando o calculo do limite: " + symbol); } } //bmf else { // BMF // account = er.IsSetField(Tags.Account)? Convert.ToInt32(er.Account.getValue()): 0; LimitResponse ret = null; string side = er.Side.getValue() == '1' ? "C" : "V"; switch (er.OrdStatus.getValue()) { case OrdStatus.NEW: ret = LimiteManager.LimitControl.GetInstance() .UpdateOperationalLimitBMF(Convert.ToInt32(er.Account.getValue()), to.TipoLimite, er.Symbol.getValue(), Convert.ToInt32(er.OrderQty.getValue()), 0, side); break; case OrdStatus.REPLACED: { int qtdResult = (-1) * (to.Order.OrderQty - to.Order.CumQty); ret = LimiteManager.LimitControl.GetInstance() .UpdateOperationalLimitBMF(Convert.ToInt32(er.Account.getValue()), to.TipoLimite, er.Symbol.getValue(), qtdResult, Convert.ToInt32(er.OrderQty.getValue()), side); } break; case OrdStatus.CANCELED: { int qtdResult = (-1) * (to.Order.OrderQty - to.Order.CumQty); ret = LimiteManager.LimitControl.GetInstance() .UpdateOperationalLimitBMF(Convert.ToInt32(er.Account.getValue()), to.TipoLimite, er.Symbol.getValue(), qtdResult, 0, side); } break; // Atualizando a quantidade de case OrdStatus.FILLED: case OrdStatus.PARTIALLY_FILLED: if (null != to.Order) { to.Order.CumQty = Convert.ToInt32(er.CumQty.getValue()); } break; } } } } #endregion // Efetuar verificacao da integracao utilizada, para efetuar a conversao do switch (this.Config.IntegrationID) { case IntegrationId.BBG: this._sendMessageBBGIntegration(msgType, msgQF, to, account); break; case IntegrationId.GRD: case IntegrationId.IVF: default: this._sendDefaultMessageIntegration(msgQF, to, account); break; } } } catch (Exception ex) { logger.Error("_processMessage(): " + ex.Message, ex); } }
public void OnMessage(QuickFix.FIX44.NewOrderSingle n, SessionID s) { Symbol symbol = n.Symbol; Side side = n.Side; OrdType ordType = n.OrdType; OrderQty orderQty = n.OrderQty; Price price = n.Price; ClOrdID clOrdID = n.ClOrdID; if (ordType.getValue() != OrdType.LIMIT) throw new IncorrectTagValue(ordType.Tag); QuickFix.FIX44.ExecutionReport exReport = new QuickFix.FIX44.ExecutionReport( new OrderID(GenOrderID()), new ExecID(GenExecID()), new ExecType(ExecType.FILL), new OrdStatus(OrdStatus.FILLED), symbol, //shouldn't be here? side, new LeavesQty(0), new CumQty(orderQty.getValue()), new AvgPx(price.getValue())); exReport.Set(clOrdID); exReport.Set(symbol); exReport.Set(orderQty); exReport.Set(new LastQty(orderQty.getValue())); exReport.Set(new LastPx(price.getValue())); if (n.IsSetAccount()) exReport.SetField(n.Account); try { Session.SendToTarget(exReport, s); } catch (SessionNotFound ex) { Console.WriteLine("==session not found exception!=="); Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine("==unknown exception=="); Console.WriteLine(ex.ToString()); Console.WriteLine(ex.StackTrace); } }