예제 #1
0
        public IEnumerable <BookData> RequestBook(string[] symbols)
        {
            var url  = BOOKS_URL + SYMBOLS_ARG + string.Join(",", symbols);
            var json = Request(url).Result;

            if (json == null)
            {
                yield break;
            }
            if (!(json is JObject))
            {
                yield break;
            }

            JObject jobject = json as JObject;

            foreach (var bookProperty in jobject.Children <JProperty>())
            {
                BookData book = BookData.FromJson(bookProperty);
                if (book != null)
                {
                    yield return(book);
                }
            }
        }
예제 #2
0
        public void BookDataFromJson()
        {
            var json = JsonConvert.DeserializeObject(
                @"{
    ""YELP"": {
        ""bids"": [
            {
                ""price"": 63.09,
                ""size"": 300,
                ""timestamp"": 1494538496261
            },
        ],
        ""asks"": [
            {
                ""price"": 63.92,
                ""size"": 300,
                ""timestamp"": 1494538381896
            },
            {
                ""price"": 63.97,
                ""size"": 300,
                ""timestamp"": 1494538381885
            }
        ]
    }
}");

            Assert.IsNotNull(json);
            Assert.IsInstanceOfType(json, typeof(JObject));

            var yelpProperty = (json as JObject).First as JProperty;

            var bookData = BookData.FromJson(yelpProperty);

            Assert.IsNotNull(bookData);

            Assert.AreEqual("YELP", bookData.Symbol);

            Assert.IsNotNull(bookData.Bids);
            Assert.AreEqual(1, bookData.Bids.Count);
            {
                var bid0 = bookData.Bids[0];
                Assert.AreEqual(63.09m, bid0.Price);
                Assert.AreEqual(300, bid0.Size);
            }

            Assert.IsNotNull(bookData.Asks);
            Assert.AreEqual(2, bookData.Asks.Count);
            {
                var ask0 = bookData.Asks[0];
                Assert.AreEqual(63.92m, ask0.Price);
                Assert.AreEqual(300, ask0.Size);
            }
            {
                var ask1 = bookData.Asks[1];
                Assert.AreEqual(63.97m, ask1.Price);
                Assert.AreEqual(300, ask1.Size);
            }
        }