Example #1
0
        /// <summary>
        /// Parses a string to a properly typed value based on the FIX tag.
        /// </summary>
        /// <param name="tag">Determines the datatype of the conversion.</param>
        /// <param name="value">A string representing a value.</param>
        public static object Parse(Tag tag, string value)
        {
            // Use the FIX tag to determine the parsing method and target data type.
            switch (tag)
            {
            case Tag.GapFillFlag:
            case Tag.IOINaturalFlag:
            case Tag.PossDupFlag:
            case Tag.ResetSeqNumFlag:

                // Boolean Values
                return(value == "Y" ? true : false);


            case Tag.BeginSeqNo:
            case Tag.BodyLength:
            case Tag.CheckSum:
            case Tag.EncodedTextLen:
            case Tag.EndSeqNo:
            case Tag.HeartBtInt:
            case Tag.InternalRecordId:
            case Tag.MsgSeqNum:
            case Tag.NewSeqNo:
            case Tag.NextExpectedMsgSeqNum:
            case Tag.NoIOIQualifiers:
            case Tag.NoRoutingIDs:
            case Tag.RawDataLength:
            case Tag.RefSeqNum:

                // Int32 Values
                return(Int32.Parse(value));

            case Tag.AvgPx:
            case Tag.Commission:
            case Tag.CxlQty:
            case Tag.CMSLeavesQty:
            case Tag.CumQty:
            case Tag.DiscretionOffset:
            case Tag.LastPx:
            case Tag.LastShares:
            case Tag.LeavesQty:
            case Tag.MaxFloor:
            case Tag.MinQty:
            case Tag.OrderQty:
            case Tag.PegDifference:
            case Tag.Price:
            case Tag.StopPx:
            case Tag.StrikePrice:

                // Decimal Values
                return(Decimal.Parse(value));

            case Tag.ExpireTime:
            case Tag.OrigSendingTime:
            case Tag.SendingTime:
            case Tag.TransactTime:
            case Tag.ValidUntilTime:

                // DateTime Values
                int year   = Int32.Parse(value.Substring(0, 4));
                int month  = Int32.Parse(value.Substring(4, 2));
                int day    = Int32.Parse(value.Substring(6, 2));
                int hour   = Int32.Parse(value.Substring(9, 2));
                int minute = Int32.Parse(value.Substring(12, 2));
                int second = Int32.Parse(value.Substring(15, 2));
                return(new DateTime(year, month, day, hour, minute, second));

            case Tag.MaturityMonthYear:

                int expYear  = Int32.Parse(value.Substring(0, 4));
                int expMonth = Int32.Parse(value.Substring(4, 2));
                return(new DateTime(expYear, expMonth, 1));

            //enums
            case Tag.BusinessRejectReason: return(BusinessRejectReasonConverter.ConvertFrom(value));

            case Tag.CxlRejReason: return(CxlRejReasonConverter.ConvertFrom(value));

            case Tag.CxlRejResponseTo: return(CxlRejResponseToConverter.ConvertFrom(value));

            case Tag.CxlType: return(CxlTypeConverter.ConvertFrom(value));

            case Tag.CommType: return(CommTypeConverter.ConvertFrom(value));

            case Tag.DiscretionInst: return(DiscretionInstConverter.ConvertFrom(value));

            case Tag.DKReason: return(DKReasonConverter.ConvertFrom(value));

            case Tag.EncryptMethod: return(EncryptMethodConverter.ConvertFrom(value));

            case Tag.ExecTransType: return(ExecTransTypeConverter.ConvertFrom(value));

            case Tag.ExecType: return(ExecTypeConverter.ConvertFrom(value));

            case Tag.HandlInst: return(HandlInstConverter.ConvertFrom(value));

            case Tag.IOIQualifier: return(IoiQualifierConverter.ConvertFrom(value));

            case Tag.IOIQltyInd: return(IOIQltyIndConverter.ConvertFrom(value));

            case Tag.IOITransType: return(IOITransTypeConverter.ConvertFrom(value));

            case Tag.LastCapacity: return(LastCapacityConverter.ConvertFrom(value));

            case Tag.MsgType: return(MsgTypeConverter.ConvertFrom(value));

            case Tag.RefMsgType: return(MsgTypeConverter.ConvertFrom(value));

            case Tag.OpenClose: return(OptionPositionTypeConverter.ConvertFrom(value));

            case Tag.PutOrCall: return(OptionTypeConverter.ConvertFrom(value));

            case Tag.OrdRejReason: return(OrdRejReasonConverter.ConvertFrom(value));

            case Tag.OrdStatus: return(OrdStatusConverter.ConvertFrom(value));

            case Tag.OrdType: return(OrdTypeConverter.ConvertFrom(value));

            case Tag.RoutingType: return(RoutingTypeConverter.ConvertFrom(value));

            case Tag.SecurityType: return(SecurityTypeConverter.ConvertFrom(value));

            case Tag.SessionRejectReason: return(SessionRejectReasonConverter.ConvertFrom(value));

            case Tag.Side: return(SideConverter.ConvertFrom(value));

            case Tag.TimeInForce: return(TimeInForceConverter.ConvertFrom(value));


            default:
                // String Values
                return(value);
            }
        }