Exemple #1
0
        public static BookData FromJson(JProperty json)
        {
            if (json == null)
            {
                return(null);
            }

            var      symbol   = json.Name;
            BookData bookData = new BookData(symbol);
            var      value    = json.Value as JObject;

            if (value != null)
            {
                Action <List <BookPrice>, BookPriceType, JArray> parsePrices = (prices, priceType, jarray) =>
                {
                    foreach (var priceJson in jarray.Children <JObject>())
                    {
                        var price = BookPrice.FromJson(priceJson, priceType);
                        if (price != null)
                        {
                            prices.Add(price);
                        }
                    }
                };

                var bids = value.GetValue(BIDS_KEY) as JArray;
                parsePrices(bookData.Bids, BookPriceType.BID, bids);

                var asks = value.GetValue(ASKS_KEY) as JArray;
                parsePrices(bookData.Asks, BookPriceType.ASK, asks);
            }
            return(bookData);
        }
Exemple #2
0
        public static BookPrice FromJson(JObject json, BookPriceType type)
        {
            BookPrice bookPrice = new BookPrice(type)
            {
                Price     = JsonHelper.GetDecimalValue(json, PRICE_KEY),
                Size      = JsonHelper.GetLongValue(json, SIZE_KEY),
                Timestamp = JsonHelper.GetDateTimeValue(json, TIMESTAMP_KEY)
            };

            return(bookPrice);
        }