private async void CheckCryptoCurrencies() { lastUpdate = DateTime.Now; if (!Program.positionsTable.GetAllRecords(out List <ViewData> list)) { Logger.Log("CheckCryptoCurrencies(): PositionsTable.GetAllRecords returned false"); return; } foreach (ViewData data in list) { if (data.symbol[0] != '^') { continue; } string id = data.symbol.Substring(1); IStockQuote avQuote = new AlphaVantageQuote(); bool success = await avQuote.GetCryptoQuote(id, data.buyDate, out StockQuote quote); if (success) { this.lastUpdate = quote.date; Logger.Log(String.Format($"CheckClosingPricesAlphaVantage(): calling PositionsTable.UpdateRecord({data.symbol}, .., {quote.close.ToString()})")); Program.positionsTable.UpdateRecord(data.id, quote.date, quote.highest, 0, quote.close); CheckStop(data, quote /*, 0*/); } else { Logger.Log(String.Format($"CheckCryptoCurrencies(): avQuote.GetCryptoQuote({data.symbol}) failed")); } } }
private async void CheckClosingPricesAlphaVantage() { //lastUpdate = DateTime.Now; if (!Program.positionsTable.GetAllRecords(out List <ViewData> list)) { Logger.Log("CheckClosingPricesAlphaVantage(): PositionsTable.GetAllRecords returned false"); return; } foreach (ViewData data in list) { if (data.symbol[0] == '_') // non-stock position (cash, 401K, etc) { continue; } if (data.symbol[0] == '^') // Crypto-currency { continue; } IStockQuote avQuote = new AlphaVantageQuote(); DateTime start = data.buyDate; // recalculate all dividends since stock was bought Logger.Log(String.Format($"CheckClosingPricesAlphaVantage(): calling avQuote.GetQuote({data.symbol}, {start.ToShortDateString()}, ..)")); bool success = await avQuote.GetQuote(data.symbol, start, out StockQuote quote); if (success) { if (quote.highest <= data.highestClose) { quote.highest = 0; // doesn't change the existing value in the database } this.lastUpdate = quote.date; #if false // Use updated dividends (if available) for the stop calculations below success = await avQuote.GetDividends(data.symbol, data.buyDate, out decimal dividends); if (success) { if (dividends < data.dividends) { dividends = data.dividends; // retain value in database if it's higher than the calculated value. } } else { dividends = data.dividends; } #endif Logger.Log(String.Format($"CheckClosingPricesAlphaVantage(): calling PositionsTable.UpdateRecord({data.symbol}, .., {quote.close.ToString()})")); Program.positionsTable.UpdateRecord(data.id, quote.date, quote.highest, 0, quote.close); CheckStop(data, quote /*,dividends*/); } else { Logger.Log(string.Format($"CheckClosingPricesAlphaVantage(): avQuote.GetQuote('{data.symbol}') failed")); } } }