Beispiel #1
0
        public static bool TryParse(string message, out DailyWeeklyMonthlyMessage dailyWeeklyMonthlyMessage)
        {
            dailyWeeklyMonthlyMessage = default;
            DateTime timestamp    = default;
            double   high         = default;
            double   low          = default;
            double   open         = default;
            double   close        = default;
            long     periodVolume = default;
            int      openInterest = default;

            var values = message.SplitFeedMessage();
            var parsed = values.Length >= 7 &&
                         DateTime.TryParseExact(values[0], DailyWeeklyMonthlyDateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out timestamp) &&
                         double.TryParse(values[1], NumberStyles.Any, CultureInfo.InvariantCulture, out high) &&
                         double.TryParse(values[2], NumberStyles.Any, CultureInfo.InvariantCulture, out low) &&
                         double.TryParse(values[3], NumberStyles.Any, CultureInfo.InvariantCulture, out open) &&
                         double.TryParse(values[4], NumberStyles.Any, CultureInfo.InvariantCulture, out close) &&
                         long.TryParse(values[5], NumberStyles.Any, CultureInfo.InvariantCulture, out periodVolume) &&
                         int.TryParse(values[6], NumberStyles.Any, CultureInfo.InvariantCulture, out openInterest);

            if (!parsed)
            {
                return(false);
            }

            dailyWeeklyMonthlyMessage = new DailyWeeklyMonthlyMessage(timestamp, high, low, open, close, periodVolume, openInterest);
            return(true);
        }
        private static bool TryParseInner(string message, out DailyWeeklyMonthlyMessage dailyWeeklyMonthlyMessage, bool hasRequestId)
        {
            var messageDataIdIndex = hasRequestId ? 1 : 0;
            var indexBase          = messageDataIdIndex;
            var values             = message.SplitFeedMessage();

            if (values[messageDataIdIndex] == HistoricalMessageHandler.HistoricalDataId)
            {
                // protocol 6.2
                return(TryParseInnerParser(values, hasRequestId, ++indexBase, out dailyWeeklyMonthlyMessage));
            }

            // protocol <6.2
            return(TryParseInnerParser(values, hasRequestId, indexBase, out dailyWeeklyMonthlyMessage));
        }
        private static bool TryParseInnerParser(string[] values, bool hasRequestId, int indexBase, out DailyWeeklyMonthlyMessage dailyWeeklyMonthlyMessage)
        {
            dailyWeeklyMonthlyMessage = default;
            DateTime timestamp    = default;
            double   high         = default;
            double   low          = default;
            double   open         = default;
            double   close        = default;
            long     periodVolume = default;
            int      openInterest = default;

            var parsed =
                DateTime.TryParseExact(values[indexBase + 0], DailyWeeklyMonthlyDateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out timestamp) &&
                double.TryParse(values[indexBase + 1], NumberStyles.Any, CultureInfo.InvariantCulture, out high) &&
                double.TryParse(values[indexBase + 2], NumberStyles.Any, CultureInfo.InvariantCulture, out low) &&
                double.TryParse(values[indexBase + 3], NumberStyles.Any, CultureInfo.InvariantCulture, out open) &&
                double.TryParse(values[indexBase + 4], NumberStyles.Any, CultureInfo.InvariantCulture, out close) &&
                long.TryParse(values[indexBase + 5], NumberStyles.Any, CultureInfo.InvariantCulture, out periodVolume) &&
                int.TryParse(values[indexBase + 6], NumberStyles.Any, CultureInfo.InvariantCulture, out openInterest);

            if (parsed)
            {
                dailyWeeklyMonthlyMessage =
                    new DailyWeeklyMonthlyMessage(
                        timestamp,
                        high,
                        low,
                        open,
                        close,
                        periodVolume,
                        openInterest,
                        hasRequestId ? values[0] : null);
            }

            return(parsed);
        }
 public static bool TryParseWithRequestId(string message, out DailyWeeklyMonthlyMessage dailyWeeklyMonthlyMessage)
 {
     return(TryParseInner(message, out dailyWeeklyMonthlyMessage, true));
 }
 public static bool TryParse(string message, out DailyWeeklyMonthlyMessage dailyWeeklyMonthlyMessage)
 {
     return(TryParseInner(message, out dailyWeeklyMonthlyMessage, false));
 }