public void Setup() { Message = new FIXMessage(); Heartbeat = System.Text.Encoding.ASCII.GetBytes( ("8=FIX.4.2|9=72|35=0|34=000008059|52=20170531-08:18:01.768|49=SENDER..|56=RECEIVER....." + "|10=202|") .Replace("|", "\u0001")); ExecutionReport = System.Text.Encoding.ASCII.GetBytes( ("8=FIX.4.2|9=352|35=8|34=000008059|52=20170531-08:18:01.768|49=SENDER..|56=RECEIVER.....|20=0|39=2|150=2" + "|17=U201:053117:00000079:B|40=2|55=EUR/CAD|54=1|38=000900000.00|151=000000000.00|14=000900000.00|32=000100000.00|31=00001.503850" + "|6=00001.503940|64=20170602|60=20170531-08:18:01.767|75=20170531|9200=S|9300=0647|9500=00000.000000|37=0804188884|15=EUR|44=00001.504200" + "|10=197|") .Replace("|", "\u0001")); MarketDataIncrementalRefresh = System.Text.Encoding.ASCII.GetBytes( ("8=FIX.4.2|9=963|35=X|34=53677|52=20170525-00:55:16.153|49=SENDER..|56=RECEIVER.....|262=c6424b19-af74-4c17-8266-9c52ca583ad2" + "|268=8" + "|279=2|55=GBP/JPY|269=0|278=1211918436|270=144.808000|271=1000000.000000|110=0.000000|15=GBP|282=290" + "|279=2|55=GBP/JPY|269=0|278=1211918437|270=144.802000|271=2000000.000000|110=0.000000|15=GBP|282=290" + "|279=0|55=GBP/JPY|269=0|278=1211918501|270=144.809000|271=1000000.000000|110=0.000000|15=GBP|282=290|735=1|695=5" + "|279=0|55=GBP/JPY|269=0|278=1211918502|270=144.803000|271=2000000.000000|110=0.000000|15=GBP|282=290|735=1|695=5" + "|279=2|55=GBP/JPY|269=1|278=1211918438|270=144.826000|271=1000000.000000|110=0.000000|15=GBP|282=290" + "|279=2|55=GBP/JPY|269=1|278=1211918439|270=144.833000|271=2000000.000000|110=0.000000|15=GBP|282=290" + "|279=0|55=GBP/JPY|269=1|278=1211918503|270=144.828000|271=1000000.000000|110=0.000000|15=GBP|282=290|735=1|695=5" + "|279=0|55=GBP/JPY|269=1|278=1211918504|270=144.834000|271=2000000.000000|110=0.000000|15=GBP|282=290|735=1|695=5" + "|10=070|") .Replace("|", "\u0001")); }
public void GetFIXTagFromMessage() { StringBuilder sb = new StringBuilder(); FileStream fileStream = new FileStream("./Application/FIXClientSpec/TestData/simplefix.txt", FileMode.Create); FIXMessage message = new FIXMessage(); message.BeginString = "FIX 4.2"; message.AvgPx = 12.21F; Type type = message.GetType(); foreach (var pi in type.GetProperties()) { var value = pi.GetValue(message); var attr = pi.GetCustomAttribute <FIXTagAttribute>(); if (attr != null) { sb.AppendFormat("{0:d}={1}\u0001", attr.Tag, value); var rawData = Encoding.UTF8.GetBytes(string.Format("{0:d}={1}\u0001", attr.Tag, value)); Console.WriteLine(attr.Tag); fileStream.Write(rawData, 0, rawData.Length); } } Console.WriteLine(sb.ToString()); fileStream.Flush(); }
public ExecutionReport this[int index] { get { FIXMessage message = this.messages[index]; return(new ExecutionReport(message)); } }
public void writes_the_whole_message_to_the_given_buffer_starting_at_the_correct_offset() { var message = new FIXMessage(); var logon = "8=FIX.4.2|9=70|35=A|34=1|52=20170607-12:17:52.355|49=DAEV|56=TARGET|98=0|108=5|141=Y|10=231|".Replace("|", "\u0001"); var bytes = logon.AsBytes(); var target = new byte[100]; message .Parse(bytes, 0, bytes.Length) .WriteTo(target, 3); var result = System.Text.Encoding.ASCII.GetString(target); result.Should().Be("\0\0\0" + logon + "\0\0\0\0\0"); }
public void Setup() { Message = new FIXMessage(); Heartbeat = System.Text.Encoding.ASCII.GetBytes( ("8=FIX.4.2|9=72|35=0|34=000008059|52=20170531-08:18:01.768|49=SENDER..|56=RECEIVER....." + "|10=202|") .Replace("|", "\u0001")); ExecutionReport = System.Text.Encoding.ASCII.GetBytes( ("8=FIX.4.2|9=352|35=8|34=000008059|52=20170531-08:18:01.768|49=SENDER..|56=RECEIVER.....|20=0|39=2|150=2" + "|17=U201:053117:00000079:B|40=2|55=EUR/CAD|54=1|38=000900000.00|151=000000000.00|14=000900000.00|32=000100000.00|31=00001.503850" + "|6=00001.503940|64=20170602|60=20170531-08:18:01.767|75=20170531|9200=S|9300=0647|9500=00000.000000|37=0804188884|15=EUR|44=00001.504200" + "|10=197|") .Replace("|", "\u0001")); MarketDataIncrementalRefresh = System.Text.Encoding.ASCII.GetBytes( ("8=FIX.4.2|9=963|35=X|34=53677|52=20170525-00:55:16.153|49=SENDER..|56=RECEIVER.....|262=c6424b19-af74-4c17-8266-9c52ca583ad2" + "|268=8" + "|279=2|55=GBP/JPY|269=0|278=1211918436|270=144.808000|271=1000000.000000|110=0.000000|15=GBP|282=290" + "|279=2|55=GBP/JPY|269=0|278=1211918437|270=144.802000|271=2000000.000000|110=0.000000|15=GBP|282=290" + "|279=0|55=GBP/JPY|269=0|278=1211918501|270=144.809000|271=1000000.000000|110=0.000000|15=GBP|282=290|735=1|695=5" + "|279=0|55=GBP/JPY|269=0|278=1211918502|270=144.803000|271=2000000.000000|110=0.000000|15=GBP|282=290|735=1|695=5" + "|279=2|55=GBP/JPY|269=1|278=1211918438|270=144.826000|271=1000000.000000|110=0.000000|15=GBP|282=290" + "|279=2|55=GBP/JPY|269=1|278=1211918439|270=144.833000|271=2000000.000000|110=0.000000|15=GBP|282=290" + "|279=0|55=GBP/JPY|269=1|278=1211918503|270=144.828000|271=1000000.000000|110=0.000000|15=GBP|282=290|735=1|695=5" + "|279=0|55=GBP/JPY|269=1|278=1211918504|270=144.834000|271=2000000.000000|110=0.000000|15=GBP|282=290|735=1|695=5" + "|10=070|") .Replace("|", "\u0001")); Configuration = new Configuration { Version = "FIX.4.2", Sender = "RECEIVER.....", Target = "SENDER..", HeartbeatInterval = 5000, OutboundSeqNum = 1, InboundSeqNum = 1 }; Transport = new Canned(); Session = new Session(Configuration, new RealTimeClock(), Transport, null, 65536, 4096, 1024); }
protected void ConvertMessage(QuickFix.Message srcMessage, FIXMessage dstMessage) { foreach (Field field1 in srcMessage) { int field2 = field1.getField(); switch (EFIXFieldTypes.GetFIXType(field2)) { case FIXType.Bool: dstMessage.SetBoolValue(field2, srcMessage.getBoolean(field2)); continue; case FIXType.Int: dstMessage.SetIntValue(field2, srcMessage.getInt(field2)); continue; case FIXType.Double: dstMessage.SetDoubleValue(field2, srcMessage.getDouble(field2)); continue; case FIXType.Char: dstMessage.SetCharValue(field2, srcMessage.getChar(field2)); continue; case FIXType.String: dstMessage.SetStringValue(field2, srcMessage.getString(field2)); continue; case FIXType.DateTime: DateTime? nullable = new DateTime?(); if (!nullable.HasValue) { try { nullable = new DateTime?(srcMessage.getUtcTimeStamp(field2)); } catch { } } if (!nullable.HasValue) { try { nullable = new DateTime?(srcMessage.getUtcDateOnly(field2)); } catch { } } if (!nullable.HasValue) { try { nullable = new DateTime?(srcMessage.getUtcTimeOnly(field2)); } catch { } } if (nullable.HasValue) { dstMessage.SetDateTimeValue(field2, nullable.Value); continue; } else continue; default: continue; } } }
/// <summary> /// Apply ticker defaults /// </summary> /// <param name="sExchange"></param> /// <param name="message"></param> public void ApplyDefaults(string sExchange, FIXMessage message) { int iClientID; if (!message.GetNumber(out iClientID, MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESAccountID) && m_nAccountID.HasValue) message.set_AsNumber(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESAccountID, (int)m_nAccountID.Value); TickerDefaults tickerDefaults = GetTickerDefaults(sExchange); if (tickerDefaults != null) { tickerDefaults.ApplyTickerDefaults(message); } }
internal ExecutionReport(FIXMessage message) { this.message = message; }
/// <summary> /// Apply ticker defaults /// </summary> /// <param name="sExchange"></param> /// <param name="message"></param> public void ApplyDefaults(string sExchange, FIXMessage message,Hashtable map) { TickerDefaults tickerDefaults = GetTickerDefaults(sExchange); if (tickerDefaults != null) { tickerDefaults.ApplyTickerDefaults(message,map); } }
/// <summary> /// Apply order details /// </summary> /// <param name="message"></param> /// <returns></returns> public bool ApplyOrderDetails(FIXMessage message) { bool bRetVal = true; //add details message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESTickerMnemonic,m_sESTickerMnemonic); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESTickerSymbol,m_sESTickerSymbol); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESExchange, ESExchange); message.set_AsNumber(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESPriceFormatCode,m_lESPriceFormatCode); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagSecurityExchange, SecurityExchange); message.set_AsNumber(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagPutOrCall, m_nOptionType); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagSecurityType, CommodityType); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagSymbol,m_sSymbol); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESStrategyCode,m_sStrategyCode); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagSecurityID,m_sSecurityID); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagIDSource,m_sIDSource); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagCFICode,m_sCFICode); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagCurrency,m_sCurrency); message.set_AsNumber(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESDecimalPlaces,m_nESDecimalPlaces); message.set_AsDouble(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESUnitTickValue,m_dUnitTickValue); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESCombinedCommodityCode, m_sCombinedCommodityCode); message.set_AsString(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESClearingHouse, m_sClearingHouse); message.set_AsDouble(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESCompositeDelta, m_dCompositeDelta); message.set_AsDouble(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESShortOptAdjust, m_dESShortOptAdjust); ApplyRiskArray(message); return bRetVal; }
//to do /// <summary> /// Basic defaults that are hard coded and not required /// </summary> /// <param name="message"></param> private void AddConstants(FIXMessage message) { //cannot be arsed as eurex does not care for this fields :) - TO DO message.set_AsString(FIXTagConstants.esFIXTagOpenClose, MESSAGEFIX3Lib.FIXOpenCloseConstants.esFIXOpen); message.set_AsNumber(FIXTagConstants.esFIXTagStopPx, 0); //Confusion in eat message.set_AsString(FIXTagConstants.esFIXTagTradingSessionID, MESSAGEFIX3Lib.FIXSessionConstants.esFIXSessionNormal); if(m_nPrimaryBOID != 0) { message.set_AsNumber(FIXTagConstants.esFIXTagESBOIDPrimary,m_nPrimaryBOID); } }
public void Setup() { Message = new FIXMessage(); Logon = "8=FIX.4.2|9=70|35=A|34=1|52=20170607-12:17:52.355|49=DAEV|56=TARGET|98=0|108=5|141=Y|10=231|".Replace("|", "\u0001"); }
/// <summary> /// Apply risk array /// </summary> /// <param name="message"></param> public void ApplyRiskArray(FIXMessage message) { ApplyRiskArray(message,m_nFIXTagESPreferredRiskArrayType); }
protected void ConvertMessage(QuickFix.Message srcMessage, FIXMessage dstMessage) { foreach (Field field1 in srcMessage) { int field2 = field1.getField(); switch (EFIXFieldTypes.GetFIXType(field2)) { case FIXType.Bool: dstMessage.SetBoolValue(field2, srcMessage.getBoolean(field2)); continue; case FIXType.Int: dstMessage.SetIntValue(field2, srcMessage.getInt(field2)); continue; case FIXType.Double: dstMessage.SetDoubleValue(field2, srcMessage.getDouble(field2)); continue; case FIXType.Char: dstMessage.SetCharValue(field2, srcMessage.getChar(field2)); continue; case FIXType.String: dstMessage.SetStringValue(field2, srcMessage.getString(field2)); continue; case FIXType.DateTime: DateTime?nullable = new DateTime?(); if (!nullable.HasValue) { try { nullable = new DateTime?(srcMessage.getUtcTimeStamp(field2)); } catch { } } if (!nullable.HasValue) { try { nullable = new DateTime?(srcMessage.getUtcDateOnly(field2)); } catch { } } if (!nullable.HasValue) { try { nullable = new DateTime?(srcMessage.getUtcTimeOnly(field2)); } catch { } } if (nullable.HasValue) { dstMessage.SetDateTimeValue(field2, nullable.Value); continue; } else { continue; } default: continue; } } }
protected void SetUserDefinedFields(FIXMessage Message, QuickFix.Message message) { foreach (FIXField fixField in Message.Fields) { if (fixField.Tag >= 500) { switch (fixField.FIXType) { case FIXType.Bool: message.setField(new BooleanField(fixField.Tag, ((FIXBoolField)fixField).Value)); continue; case FIXType.Int: message.setField(new IntField(fixField.Tag, ((FIXIntField)fixField).Value)); continue; case FIXType.Double: message.setField(new DoubleField(fixField.Tag, ((FIXDoubleField)fixField).Value)); continue; case FIXType.Char: message.setField(new CharField(fixField.Tag, ((FIXCharField)fixField).Value)); continue; case FIXType.String: message.setField(new StringField(fixField.Tag, ((FIXStringField)fixField).Value)); continue; case FIXType.DateTime: message.setField((UtcDateOnlyField)new UtcDateField(fixField.Tag, ((FIXDateTimeField)fixField).Value)); continue; default: continue; } } } }
/// <summary> /// Apply risk array to fix order message /// </summary> /// <param name="message"></param> /// <param name="riskArray"></param> public void ApplyRiskArray(FIXMessage message,string[] riskArray) { if(riskArray.Length > 0) { FIXGroup group = message.AddGroup(MESSAGEFIX3Lib.FIXTagConstants.esFIXTagESNoRiskArrays); if (group != null) { for (int i = 0; i < riskArray.Length; i++) { if (riskArray[i].Length > 0) { try { FIXGroup subgroup = group.AddGroup(null); if (subgroup != null) { subgroup.set_AsString(EASYROUTERCOMCLIENTLib.FIXTagConstants.esFIXTagESRiskArrayValue, riskArray[i]); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); } } } } } }
/// <summary> /// Apply risk array to fix order message /// </summary> /// <param name="message"></param> /// <param name="nFIXTagESPreferredRiskArrayType"></param> public void ApplyRiskArray(FIXMessage message,int nFIXTagESPreferredRiskArrayType ) { //MESSAGEFIX3Lib.FIXESRiskArrayTypeConstants if (m_RiskMap.ContainsKey(nFIXTagESPreferredRiskArrayType)) { ApplyRiskArray(message, (string[])m_RiskMap[nFIXTagESPreferredRiskArrayType]); } else { if(m_RiskMap.ContainsKey((int)MESSAGEFIX3Lib.FIXESRiskArrayTypeConstants.esFIXESRiskArrayTypeESExternalFeed)) { ApplyRiskArray(message, (string[])m_RiskMap[(int)MESSAGEFIX3Lib.FIXESRiskArrayTypeConstants.esFIXESRiskArrayTypeESExternalFeed]); } else if(m_RiskMap.ContainsKey((int)MESSAGEFIX3Lib.FIXESRiskArrayTypeConstants.esFIXESRiskArrayTypeESIntraday)) { ApplyRiskArray(message, (string[])m_RiskMap[(int)MESSAGEFIX3Lib.FIXESRiskArrayTypeConstants.esFIXESRiskArrayTypeESIntraday]); } else if(m_RiskMap.ContainsKey((int)MESSAGEFIX3Lib.FIXESRiskArrayTypeConstants.esFIXESRiskArrayTypeESSettlement)) { ApplyRiskArray(message, (string[])m_RiskMap[(int)MESSAGEFIX3Lib.FIXESRiskArrayTypeConstants.esFIXESRiskArrayTypeESSettlement]); } } }
/// <summary> /// Add Custom Ticker Defaults Tag /// </summary> /// <param name="message"></param> /// <param name="map"></param> public void ApplyTickerDefaults(FIXMessage message,Hashtable map) { IDictionaryEnumerator it = map.GetEnumerator(); while (it.MoveNext()) { if(this.ContainsKey(it.Key)) if (it.Value.ToString() != string.Empty) message.set_AsString((MESSAGEFIX3Lib.FIXTagConstants)it.Key, it.Value.ToString()); } }
/// <summary> /// Function to process data off the tcp stream - called from the worker thread /// </summary> public void ReadStream() { try { MESSAGEFIX3Lib.FIXMessage msg = new FIXMessage(); char[] message = new char[1024]; while (m_bContinue) { int nSize = m_StreamIn.ReadBlock(message, 0, 1024); if (nSize <= 0) continue; #if DEBUG System.Diagnostics.Trace.WriteLine("In Buffer" + nSize); #endif m_sTCPBuffer.Append(message, 0, nSize); #if DEBUG System.Diagnostics.Trace.WriteLine(m_sTCPBuffer.ToString()); #endif bool bContinue = true; while(bContinue) { string sData = m_sTCPBuffer.ToString(); int nheader = sData.IndexOf("8="); int nTail = sData.IndexOf("10="); if (nTail <= 0) { bContinue = false; continue; } int nEnd = sData.IndexOf("!", nTail); int nEnd1 = sData.IndexOf("8=", nTail); if (nEnd1 == -1) { bContinue = false; } else { sData = sData.Substring(nheader, nEnd1 - nheader); #if DEBUG System.Diagnostics.Trace.WriteLine("Buffer Current" + m_sTCPBuffer.Length); #endif m_sTCPBuffer.Remove(0, nEnd1); #if DEBUG System.Diagnostics.Trace.WriteLine("Buffer Data Remainder" + m_sTCPBuffer.Length); #endif //find the specific string string sTemp = string.Empty; //parse fix messagge bool bSuccess = msg.Parse(sData, m_sDelimiter, false); if (bSuccess) { if (DataEvent != null) { DataEvent(this, new FIXMessageEventArgs(msg)); } } else { //Failed to parse data #if DEBUG System.Diagnostics.Trace.WriteLine("Parse Error = " + sTemp); #endif } //clear the object msg.Clear(); } } } } catch (Exception e) { //Log - raise an event if (DisconnectEvent != null) DisconnectEvent(new ErrorEventArgs(e)); } }
//TODO: [16/04/07] YKC - Hack as i donot care about order types etc /// <summary> /// Generate a fix message /// </summary> /// <param name="MsgType"></param> /// <returns></returns> public FIXMessage CreateFixMessage(MESSAGEFIX3Lib.FIXMsgConstants MsgType) { FIXMessage message = new FIXMessage(); if (Instrument != null) { message.MsgType = MsgType; Instrument.ApplyOrderDetails(message); AddConstants(message); //Add order details if (m_dPrice.HasValue) message.set_AsDouble(FIXTagConstants.esFIXTagPrice, m_dPrice.Value); message.set_AsNumber(FIXTagConstants.esFIXTagOrderQty, (int)m_nOrderQty); message.set_AsString(FIXTagConstants.esFIXTagSide, m_sSide); message.set_AsString(FIXTagConstants.esFIXTagTimeInForce, GetFIXTimeInForce()); message.set_AsString(FIXTagConstants.esFIXTagOrdType, GetFIXOrderType()); if (m_iAccountID.HasValue) message.set_AsNumber(FIXTagConstants.esFIXTagESAccountID, (int)m_iAccountID.Value); return message; } return null; }