public OrderBookData Retrieve()
        {
            var we = new WebClient();

            we.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36");

            var nameValueCollection = new NameValueCollection();

            nameValueCollection.Add("symbol", _securityName);

            var results = we.UploadValues(BaseOrdersUri + "/orderbook", nameValueCollection);
            var json    = Encoding.ASCII.GetString(results);

            var data = new OrderBookData();
            var havelockOrderBook = JsonConvert.DeserializeObject <HavelockOrderBookJson>(json);

            data.Bids = ToOrders(havelockOrderBook.bids);
            data.Asks = ToOrders(havelockOrderBook.asks);

            data.Source = this;
            return(data);
        }
Exemple #2
0
        public OrderBookData Retrieve()
        {
            using (var wc = new WebClient())
            {
                wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36");
                string results = wc.DownloadString(new Uri(BaseOrdersUri + _securityName));

                results = Regex.Replace(results, ",\"generated\":.*}", "}");
                var orderBookData = new OrderBookData();

                var orderBook = JsonConvert.DeserializeObject <Dictionary <string, BtctOrderBookJson> >(results).Select(s => s.Value);
                orderBookData.Asks = orderBook.Where(o => o.buy_sell == "ask").Select(o => new OrderBookOrder {
                    Quantity = o.quantity, Amount = o.amount
                });
                orderBookData.Bids = orderBook.Where(o => o.buy_sell == "bid").Select(o => new OrderBookOrder {
                    Quantity = o.quantity, Amount = o.amount
                });
                orderBookData.Source = this;

                return(orderBookData);
            }
        }