private PriceQuantityCollection GetOrders(string ordersJson, decimal convertRate) { JArray asksJArray = JArray.Parse(ordersJson); PriceQuantityCollection orders = new PriceQuantityCollection(); foreach (var item in asksJArray) { List <decimal> itemResult = JsonConvert.DeserializeObject <List <decimal> >(item.ToString()); PriceQuantityItem order = new PriceQuantityItem(); order.ConvertRate = convertRate; order.Price = itemResult[0]; order.Quantity = itemResult[1]; orders.Add(order); } return(orders); }
private PriceQuantityCollection GetOrders(string ordersJson, decimal convertRate) { JArray asksJArray = JArray.Parse(ordersJson); PriceQuantityCollection orders = new PriceQuantityCollection(); foreach (var item in asksJArray) { var def = new { count = 0, rate = 0m, vol = 0m }; var result = JsonConvert.DeserializeAnonymousType(item.ToString(), def); PriceQuantityItem order = new PriceQuantityItem(); order.ConvertRate = convertRate; order.Price = result.rate; order.Quantity = result.vol; orders.Add(order); } return(orders); }
private void UpdateQuotation(Quotation quotation, string json) { JObject jObject = JObject.Parse(json); decimal convertRate = quotation.Ticker.ConvertRate; string bids = jObject["bids"].ToString(); quotation.BuyOrders = GetOrders(bids, convertRate); string asks = jObject["asks"].ToString(); PriceQuantityCollection sellOrders = GetOrders(asks, convertRate); var reverse = sellOrders.Reverse(); var reverseOrders = new PriceQuantityCollection(); foreach (PriceQuantityItem order in reverse) { reverseOrders.Add(order); } quotation.SellOrders = reverseOrders; }
// /// <summary> /// 从Api的Json数据获取订单。 /// </summary> /// <param name="ordersJson"></param> /// <returns></returns> /// <example> /// {"price":"0.00000034","quantity":"0.00000000","total":"23.04005139"}, /// </example> private PriceQuantityCollection GetOrders(string ordersJson, decimal convertRate) { //当心买盘为0时orderJson为空! try { JArray asksJArray = JArray.Parse(ordersJson); PriceQuantityCollection orders = new PriceQuantityCollection(); foreach (var item in asksJArray) { var itemDef = new { price = 0m, quantity = 0m }; var itemResult = JsonConvert.DeserializeAnonymousType(item.ToString(), itemDef); PriceQuantityItem order = new PriceQuantityItem(); order.ConvertRate = convertRate; order.Price = itemResult.price; order.Quantity = itemResult.quantity; orders.Add(order); } return(orders); } catch { return(new PriceQuantityCollection()); } }