private List<Ticker> parseTickerList(string s) { List<Ticker> lt = new List<Ticker>(); JObject r; try { r = JObject.Parse(s); } catch (Newtonsoft.Json.JsonReaderException ex) { throw (new BTCTException("Invalid response format.")); } foreach (JProperty ch in r.Children()) { Ticker t = new Ticker(); string tname = ch.Name; JToken c = ch.First; t = parseTicker(c); t.name = tname; lt.Add(t); } return lt; }
private Ticker parseTicker(JToken j) { Ticker t = new Ticker(); string temp; t.type = BTCTUtils.StringToSecurityType((string)j["type"]); t.last = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["last_price"])); t.lastQty = Convert.ToInt32(BTCTUtils.ParseTickerString((string)j["last_qty"])); t.bid = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["bid"])); t.ask = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["ask"])); t.lo1d = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["24h_low"])); t.hi1d = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["24h_high"])); t.av1d = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["24h_avg"])); // Volume data comes in the form "quantity@BTCvolume" temp = ((string)j["24h_vol"]); if (temp == "--") { t.vol1d = 0; t.volBTC1d = 0; } else { t.vol1d = Convert.ToInt32(temp.Split(new Char[] { '@' })[0]); t.volBTC1d = BTCTUtils.StringToSatoshi(temp.Split(new Char[] { '@' })[1]); } t.lo7d = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["7d_low"])); t.hi7d = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["7d_high"])); t.av7d = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["7d_avg"])); temp = ((string)j["7d_vol"]); if (temp == "--") { t.vol7d = 0; t.volBTC7d = 0; } else { t.vol7d = Convert.ToInt32(temp.Split(new Char[] { '@' })[0]); t.volBTC7d = BTCTUtils.StringToSatoshi(temp.Split(new Char[] { '@' })[1]); } t.lo30d = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["30d_low"])); t.hi30d = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["30d_high"])); t.av30d = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["30d_avg"])); temp = ((string)j["30d_vol"]); if (temp == "--") { t.vol30d = 0; t.volBTC30d = 0; } else { t.vol30d = Convert.ToInt32(temp.Split(new Char[] { '@' })[0]); t.volBTC30d = BTCTUtils.StringToSatoshi(temp.Split(new Char[] { '@' })[1]); } t.totalVol = BTCTUtils.StringToSatoshi(BTCTUtils.ParseTickerString((string)j["total_vol"])); return t; }