Beispiel #1
0
        /// <summary>
        /// Creates from string.
        /// </summary>
        /// <param name="rawBookUpdateMessage">The raw book update message.</param>
        /// <returns></returns>
        public static BookUpdateMessage CreateFromString(string rawBookUpdateMessage)
        {
            var bookUpdateMessage = KrakenDataMessageHelper.EnsureRawMessage(rawBookUpdateMessage);

            var asks = bookUpdateMessage.Skip(1).OfType <JObject>().FirstOrDefault(x => x.ContainsKey("a"));
            var bids = bookUpdateMessage.Skip(1).OfType <JObject>().FirstOrDefault(x => x.ContainsKey("b"));

            return(new BookUpdateMessage
            {
                ChannelId = Convert.ToInt64(bookUpdateMessage.First),
                Asks = asks != null ? asks["a"].OfType <JArray>().Select(level => PriceLevel.CreateFromJArray(level)).ToArray() : null,
                Bids = bids != null ? bids["b"].OfType <JArray>().Select(level => PriceLevel.CreateFromJArray(level)).ToArray() : null,
            });
        }
Beispiel #2
0
        /// <summary>
        /// Creates from string.
        /// </summary>
        /// <param name="rawBookSnapshotMessage">The raw book snapshot message.</param>
        /// <returns></returns>
        public static BookSnapshotMessage CreateFromString(string rawBookSnapshotMessage)
        {
            var bookSnapshotTokens = KrakenDataMessageHelper.EnsureRawMessage(rawBookSnapshotMessage);
            var detailTokens       = (JObject)bookSnapshotTokens[1];

            return(new BookSnapshotMessage
            {
                ChannelId = Convert.ToInt64(bookSnapshotTokens.First),
                Asks = ((JArray)detailTokens["as"]).OfType <JArray>().Select(level => PriceLevel.CreateFromJArray(level)).ToArray(),
                Bids = ((JArray)detailTokens["bs"]).OfType <JArray>().Select(level => PriceLevel.CreateFromJArray(level)).ToArray()
            });
        }