/// <summary> Updates this object. </summary> /// /// <remarks> Paul, 31/01/2015. </remarks> async public void Update() { // ping all the daemons m_allCurrencies = m_auth.m_Database.GetAllCurrencies(); List <MarketRow> allMarkets = m_auth.m_Database.GetAllMarkets(); List <string> allDaemons = allMarkets.Select <MarketRow, string>(r => r.daemon_url).Distinct().ToList(); foreach (string daemon in allDaemons) { bool up = false; try { string response = await Rest.ExecuteGetAsync(ApiUrl(daemon, Routes.kGetAllMarkets), 5000); ApiError exception = GetExceptionFromResult(response); if (exception == null) { List <MarketRow> daemonMarkets = JsonSerializer.DeserializeFromString <List <MarketRow> >(response); foreach (MarketRow m in daemonMarkets) { m_auth.m_Database.UpdateMarketInDatabase(m); } up = true; } } catch (Exception) { up = false; } m_auth.m_Database.UpdateMarketStatus(daemon, up); } // collect market stats foreach (MarketRow r in allMarkets) { decimal btcVolume24h = m_auth.m_Database.Get24HourBtcVolume(r.symbol_pair, r.flipped); LastPriceAndDelta lastPrice = m_auth.m_Database.GetLastPriceAndDelta(r.symbol_pair); decimal realisedSpreadPercent = 100 * (1 - r.bid / r.ask); decimal qa, qb; if (r.flipped) { qb = r.ask; qa = r.bid; } else { qa = 1 / r.ask; qb = 1 / r.bid; } decimal buyFee = (qa * r.ask_fee_percent / 100); decimal sellFee = (qb * r.bid_fee_percent / 100); decimal buyQuantity = qa - buyFee; decimal sellQuantity = qb + sellFee; m_Database.UpdateMarketStats(r.symbol_pair, btcVolume24h, lastPrice.last_price, lastPrice.price_delta, realisedSpreadPercent, buyQuantity, sellQuantity); } }