/// <remarks> /// { /// "result":true, /// "order": /// { /// "id":"15088", /// "status":"cancelled", /// "pair":"btc_cny", /// "type":"sell", /// "rate":811, /// "amount":"0.39901357", /// "initial_rate":811, /// "initial_amount":"1" /// }, /// "msg":"Success" /// } /// </remarks> private Order GetOrder(string orderId) { Dictionary <string, string> orderArgs = new Dictionary <string, string>(); orderArgs.Add("order_id", orderId); string json = AuthQuery("1/private/getorder", orderArgs); JObject jObject = JObject.Parse(json); Order order = new Order(); order.Id = Convert.ToInt32(jObject["order"]["id"].ToString()); if (jObject["order"]["type"].ToString() == "sell") { order.OrderType = OrderType.Sell; } if (jObject["order"]["type"].ToString() == "buy") { order.OrderType = OrderType.Buy; } PriceQuantityItem pq = new PriceQuantityItem(); double price = Convert.ToDouble(jObject["order"]["rate"].ToString()); pq.Price = Convert.ToDecimal(price); pq.Quantity = Convert.ToDecimal(jObject["order"]["amount"].ToString()); order.PriceQuantity = pq; return(order); }
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); }
// /// <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()); } }