public void AddGroupGetGroupTest() { var nos = new QuickFix.FIX42.NewOrderSingle(); var noTradingSessions = new QuickFix.FIX42.NewOrderSingle.NoTradingSessionsGroup(); noTradingSessions.SetField(new StringField(336, "OHHAI")); nos.AddGroup(noTradingSessions); var noTradingSessionsRE = nos.GetGroup(1, Tags.NoTradingSessions); Assert.That(noTradingSessionsRE.GetString(336), Is.EqualTo("OHHAI")); var nos2 = new QuickFix.FIX42.NewOrderSingle(); var grp = new Group(200, 300); grp.SetField(new StringField(300, "Dude")); nos2.AddGroup(grp); Assert.That(nos2.GetGroup(1, 200).GetString(300), Is.EqualTo("Dude")); }
public void AddGetGroupTest() { Group g1 = new Group(100, 200); Group g2 = new Group(100, 201); MockFieldMap fm = new MockFieldMap(); fm.AddGroup(g1); fm.AddGroup(g2); Assert.That(fm.GetGroup(1, 100), Is.EqualTo(g1)); Assert.That(fm.GetGroup(2, 100), Is.EqualTo(g2)); Assert.Throws(typeof(FieldNotFoundException), delegate { fieldmap.GetGroup(0, 101); }); Assert.Throws(typeof(FieldNotFoundException), delegate { fieldmap.GetGroup(3, 100); }); Assert.Throws(typeof(FieldNotFoundException), delegate { fieldmap.GetGroup(1, 101); }); }
/// <summary> /// /// </summary> /// <param name="message">Market data snapshot full refresh message</param> /// <param name="session">Session ID</param> private void OnMessage(QuickFix.FIX43.MarketDataSnapshotFullRefresh message, QuickFix.SessionID session) { try { int numberOfMarketDataEntries = message.NoMDEntries.getValue(); for (int i = 1; i <= numberOfMarketDataEntries; i++) { Tick tick = new Tick(new Security() { Symbol = message.Symbol.getValue() }, _provider); tick.DateTime = message.Header.GetDateTime(QuickFix.Fields.Tags.SendingTime); QuickFix.Group group = message.GetGroup(i, QuickFix.Fields.Tags.NoMDEntries); if (group.GetField(QuickFix.Fields.Tags.MDEntryType).Equals("0")) { tick.BidPrice = Convert.ToDecimal(group.GetField(QuickFix.Fields.Tags.MDEntryPx)); tick.BidSize = Convert.ToDecimal(group.GetField(QuickFix.Fields.Tags.MDEntrySize)); tick.BidExchange = group.GetField(QuickFix.Fields.Tags.MDEntryOriginator); } if (group.GetField(QuickFix.Fields.Tags.MDEntryType).Equals("1")) { tick.AskPrice = Convert.ToDecimal(group.GetField(QuickFix.Fields.Tags.MDEntryPx)); tick.AskSize = Convert.ToDecimal(group.GetField(QuickFix.Fields.Tags.MDEntrySize)); tick.AskExchange = group.GetField(QuickFix.Fields.Tags.MDEntryOriginator); } if (TickArrived != null) { TickArrived(tick); } } } catch (Exception exception) { Logger.Error(exception.ToString(), _type.FullName, "OnMessage"); } }
/// <summary> /// returns a copy of src (it's only as deep as FieldMap implemented) /// </summary> /// <param name="src">the Group to copy</param> public Group(Group src) :base(src) { Field = src.Field; Delim = src.Delim; }
protected int SetGroup(StringField grpNoFld, string msgstr, int pos, FieldMap fieldMap, DataDictionary.IGroupSpec dd, DataDictionary.DataDictionary sessionDataDictionary, DataDictionary.DataDictionary appDD) { int delim = dd.Delim; int grpPos = pos; Group grp = null; while (pos < msgstr.Length) { grpPos = pos; StringField f = ExtractField(msgstr, ref pos, sessionDataDictionary, appDD); if (f.Tag == delim) { if (grp != null) { fieldMap.AddGroup(grp, false); } grp = new Group(grpNoFld.Tag, delim); } else if (!dd.IsField(f.Tag)) { if (grp != null) { fieldMap.AddGroup(grp, false); } return grpPos; } grp.SetField(f); if(dd.IsGroup(f.Tag)) { pos = SetGroup(f, msgstr, pos, grp, dd.GetGroupSpec(f.Tag), sessionDataDictionary, appDD); } } return grpPos; }
public void ClearAndIsEmptyTest() { MockFieldMap fieldmap = new MockFieldMap(); BooleanField field = new BooleanField(200, true); Assert.That(fieldmap.IsEmpty(), Is.EqualTo(true)); fieldmap.SetField(field); Assert.That(fieldmap.IsEmpty(), Is.EqualTo(false)); fieldmap.Clear(); Assert.That(fieldmap.IsEmpty(), Is.EqualTo(true)); Group g = new Group(100, 101); fieldmap.AddGroup(g); Assert.That(fieldmap.IsEmpty(), Is.EqualTo(false)); fieldmap.Clear(); Assert.That(fieldmap.IsEmpty(), Is.EqualTo(true)); }
public void GroupDelimTest() { Group g1 = new Group(100, 200); Assert.AreEqual(100, g1.Field); //counter Assert.AreEqual(200, g1.Delim); g1.SetField(new StringField(200, "delim!")); FieldMap fm = new FieldMap(); fm.AddGroup(g1); Assert.AreEqual(1, fm.GetInt(100)); Group g2 = new Group(100, 200); g2.SetField(new StringField(200, "again!")); fm.AddGroup(g2); Assert.AreEqual(2, fm.GetInt(100)); }
private void queueProc() { logger.Info("Iniciando thread de processamento da fila de mensagens FIX"); long lastLog = 0; while (_bKeepRunning) { try { QuickFix.FIX44.Message message = null; if (queueToProcess.TryDequeue(out message)) { if (logger.IsDebugEnabled) { logger.Debug("Processing Message [" + message.Header.GetInt(34) + "] type [" + message.Header.GetString(35) + "]"); } string channelID; string msgtype = message.Header.GetString(QuickFix.Fields.Tags.MsgType); switch (msgtype) { case QuickFix.FIX44.MarketDataIncrementalRefresh.MsgType: if (message.GroupCount(QuickFix.Fields.Tags.NoMDEntries) > 0) { QuickFix.Group MDEntry = message.GetGroup(1, QuickFix.Fields.Tags.NoMDEntries); string securityID = MDEntry.GetString(QuickFix.Fields.Tags.SecurityID); channelID = dctChannel.GetOrAdd(securityID, FIX_DEFAULT_WORKER); } else { channelID = FIX_DEFAULT_WORKER; } break; case QuickFix.FIX44.MarketDataSnapshotFullRefresh.MsgType: if (message.IsSetField(QuickFix.Fields.Tags.SecurityID)) { string securityID = message.GetString(QuickFix.Fields.Tags.SecurityID); channelID = dctChannel.GetOrAdd(securityID, FIX_DEFAULT_WORKER); } else { channelID = FIX_DEFAULT_WORKER; } break; case QuickFix.FIX44.SecurityList.MsgType: if (message.GroupCount(QuickFix.Fields.Tags.NoRelatedSym) > 0) { QuickFix.Group MDEntry = message.GetGroup(1, QuickFix.Fields.Tags.NoRelatedSym); string securityID = MDEntry.GetString(QuickFix.Fields.Tags.SecurityID); string securityType = MDEntry.GetString(QuickFix.Fields.Tags.SecurityType); channelID = dctChannel.GetOrAdd(securityID, securityType); } else { channelID = FIX_DEFAULT_WORKER; } break; case QuickFix.FIX44.SecurityStatus.MsgType: if (message.IsSetField(QuickFix.Fields.Tags.SecurityID)) { string securityID = message.GetString(QuickFix.Fields.Tags.SecurityID); channelID = dctChannel.GetOrAdd(securityID, FIX_DEFAULT_WORKER); } else { channelID = FIX_DEFAULT_WORKER; } break; default: channelID = FIX_DEFAULT_WORKER; break; } EventoFIX eventoFIX = new EventoFIX(); eventoFIX.ChannelID = channelID; eventoFIX.MarketDepth = ConstantesUMDF.UMDF_MARKETDEPTH_MARKET_BY_ORDER; eventoFIX.Message = message; eventoFIX.MsgSeqNum = message.Header.GetInt(QuickFix.Fields.Tags.MsgSeqNum); eventoFIX.MsgType = msgtype; eventoFIX.StreamType = StreamTypeEnum.STREAM_TYPE_TCP_CONFLATED; ContainerManager.Instance.EnqueueFIX(eventoFIX); if (MDSUtils.shouldLog(lastLog)) { logger.Info("Mensagens FIX para processar na fila: " + queueToProcess.Count); lastLog = DateTime.UtcNow.Ticks; } continue; } Thread.Sleep(25); } catch (Exception ex) { logger.Error("queueProc: " + ex.Message, ex); } } logger.Info("Thread de fila de mensagens FIX finalizada"); }
public virtual void OnMessage(QuickFix.FIX44.SecurityList message, SessionID session) { try { EventoFIX evento = new EventoFIX(); if (message.IsSetField(QuickFix.Fields.Tags.SecurityRequestResult) && message.IsSetField(QuickFix.Fields.Tags.SecurityReqID)) { string requestResult = message.GetString(QuickFix.Fields.Tags.SecurityRequestResult); if (!requestResult.Equals("0")) { logger.WarnFormat("Request [{0}] nao pode ser atendido result=[{1}]", message.GetString(QuickFix.Fields.Tags.SecurityReqID), message.GetString(QuickFix.Fields.Tags.SecurityRequestResult)); } } if (message.IsSetSecurityReqID()) { int noRelatedSym = message.GroupCount(QuickFix.Fields.Tags.NoRelatedSym); for (int i = 1; i <= noRelatedSym; i++) { QuickFix.Group relatedSyms = message.GetGroup(i, QuickFix.Fields.Tags.NoRelatedSym); string securityID = relatedSyms.GetString(QuickFix.Fields.Tags.SecurityID); string securityType = relatedSyms.GetString(QuickFix.Fields.Tags.SecurityType); dctChannel.AddOrUpdate(securityID, securityType, (key, oldValue) => securityType); } } logger.Debug("OnMessage(QuickFix.FIX44.SecurityList) Enqueue to split [" + message.Header.GetInt(QuickFix.Fields.Tags.MsgSeqNum) + "]"); enqueueToSplit(message); logger.Debug("OnMessage(QuickFix.FIX44.SecurityList) Enqueud [" + message.Header.GetInt(QuickFix.Fields.Tags.MsgSeqNum) + "]"); // Requisita a proxima lista de papeis if (message.IsSetLastFragment() && message.LastFragment.ToString().ToUpper().Equals("Y")) { if (message.IsSetSecurityReqID()) { logger.Info("Final da security list ID [" + message.SecurityReqID.ToString() + "]"); logger.Info("Solicitando snapshots"); ThreadPool.QueueUserWorkItem(new WaitCallback(RequestMarketData), session); if (_secListMarketRequested < _channelUmdfConfig.Markets.Count) { ThreadPool.QueueUserWorkItem(new WaitCallback(RequestSecurityList), session); } else { logger.Info("Final das requisicoes de securitylist"); //logger.Info("Solicitando snapshots"); //ThreadPool.QueueUserWorkItem(new WaitCallback(RequestMarketData), session); } } } } catch (Exception ex) { logger.Error("onMessage(SecurityList): " + ex.Message, ex); } }
public static void ConsistirNovaOrdemCross(NewOrderCross noc, string exchange) { string strAccount1 = string.Empty; if (!noc.IsSetCrossID()) { throw new ArgumentException("CrossID field must be provided"); } if (!noc.IsSetCrossType()) { throw new ArgumentException("CrossType field must be provided"); } if (!noc.IsSetCrossPrioritization()) { throw new ArgumentException("CrossPriorization field must be provided"); } if (noc.IsSetNoSides() && noc.NoSides.getValue() == 2) { QuickFix.Group grpNoSides = noc.GetGroup(1, Tags.NoSides); OrdensConsistencia.ProcessGroupNOC(grpNoSides); grpNoSides = noc.GetGroup(2, Tags.NoSides); OrdensConsistencia.ProcessGroupNOC(grpNoSides); } // Instrument Identification Block if (string.IsNullOrEmpty(noc.Symbol.ToString())) { throw new ArgumentException("Symbol field must be provided"); } if (exchange.Equals(ExchangePrefixes.BMF, StringComparison.InvariantCultureIgnoreCase)) { if (string.IsNullOrEmpty(noc.SecurityID.ToString())) { throw new ArgumentException("SecurityID field must be provided"); } } OrdType ordType = noc.OrdType; if (ordType == null) { throw new ArgumentException("OrdType is invalid"); } // Verifica envio do preco bool aux = false; switch (ordType.ToString()[0]) { case OrdType.LIMIT: // OrdemTipoEnum.Limitada: break; default: aux = true; break; } if (aux) { throw new ArgumentException("OrderType must be 2 - Limit"); } if (noc.IsSetPrice()) { if (noc.Price.getValue() <= new Decimal(0)) { throw new ArgumentException("Must must be >= 0"); } } }
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); } }