public static Book ParseMarketDepthBook(JObject bookJson, MarketId marketId) { JToken buyJson = bookJson["buy"]; JToken sellJson = bookJson["sell"]; if (buyJson.Type != JTokenType.Array) { throw new CryptsyResponseException("Expected array for buy-side market depth, found \"" + Enum.GetName(typeof(JTokenType), buyJson.Type) + "\"."); } if (sellJson.Type != JTokenType.Array) { throw new CryptsyResponseException("Expected array for sell-side market depth, found \"" + Enum.GetName(typeof(JTokenType), sellJson.Type) + "\"."); } JArray buyArray = (JArray)buyJson; JArray sellArray = (JArray)sellJson; List <MarketDepth> buy = buyArray.Select( depth => (MarketDepth)CryptsyMarketDepth.ParseMarketDepth(depth as JArray) ).ToList(); List <MarketDepth> sell = sellArray.Select( depth => (MarketDepth)CryptsyMarketDepth.ParseMarketDepth(depth as JArray) ).ToList(); return(new Book(sell, buy)); }
public static Book ParseMarketOrders(JObject marketOrdersJson) { List <MarketDepth> buyOrders = marketOrdersJson.Value <JArray>("buyorders").Select(marketOrder => (MarketDepth)CryptsyMarketDepth.ParseBuy(marketOrder as JObject)).ToList(); List <MarketDepth> sellOrders = marketOrdersJson.Value <JArray>("sellorders").Select(marketOrder => (MarketDepth)CryptsyMarketDepth.ParseSell(marketOrder as JObject)).ToList(); return(new Book(sellOrders, buyOrders)); }