public static bool TryParse(string message, out IntervalMessage intervalMessage)
        {
            DateTime timestamp      = default;
            double   high           = default;
            double   low            = default;
            double   open           = default;
            double   close          = default;
            long     totalVolume    = default;
            long     periodVolume   = default;
            int      numberOfTrades = default;

            var values = message.SplitFeedMessage();
            var parsed = values.Length >= 8 &&
                         DateTime.TryParseExact(values[0], IntervalDateTimeFormat, 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 totalVolume) &
                         long.TryParse(values[6], NumberStyles.Any, CultureInfo.InvariantCulture, out periodVolume) &
                         int.TryParse(values[7], NumberStyles.Any, CultureInfo.InvariantCulture, out numberOfTrades);

            intervalMessage = new IntervalMessage(timestamp, high, low, open, close, totalVolume, periodVolume, numberOfTrades);
            return(parsed);
        }
Exemple #2
0
        private static bool TryParseInner(string message, out IntervalMessage intervalMessage, 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 intervalMessage));
            }

            // protocol <6.2
            return(TryParseInnerParser(values, hasRequestId, indexBase, out intervalMessage));
        }
Exemple #3
0
        private static bool TryParseInnerParser(string[] values, bool hasRequestId, int indexBase, out IntervalMessage intervalMessage)
        {
            intervalMessage = null;
            DateTime timestamp      = default;
            double   high           = default;
            double   low            = default;
            double   open           = default;
            double   close          = default;
            long     totalVolume    = default;
            long     periodVolume   = default;
            int      numberOfTrades = default;

            var parsed =
                DateTime.TryParseExact(values[indexBase + 0], IntervalDateTimeFormat, 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 totalVolume) &&
                long.TryParse(values[indexBase + 6], NumberStyles.Any, CultureInfo.InvariantCulture, out periodVolume) &&
                int.TryParse(values[indexBase + 7], NumberStyles.Any, CultureInfo.InvariantCulture, out numberOfTrades);

            if (parsed)
            {
                intervalMessage = new IntervalMessage(
                    timestamp,
                    high,
                    low,
                    open,
                    close,
                    totalVolume,
                    periodVolume,
                    numberOfTrades,
                    hasRequestId ? values[0] : null);
            }

            return(parsed);
        }
Exemple #4
0
 public static bool TryParseWithRequestId(string message, out IntervalMessage intervalMessage)
 {
     return(TryParseInner(message, out intervalMessage, true));
 }
Exemple #5
0
 public static bool TryParse(string message, out IntervalMessage intervalMessage)
 {
     return(TryParseInner(message, out intervalMessage, false));
 }