internal static List <AlphaVantageAgent.KeyAgent> LoadKeys(AlphaVantageAgent parent) { List <AlphaVantageAgent.KeyAgent> keyAgents; string keyQuery = @"select ApiKey, coalesce(DateLastUsed, '1900-01-01') as DateLastUsed, coalesce(DailyCallCount, 0) as DailyCallCount, DailyCallMax as DailyCallMax, coalesce(CallsPerMinute, 0) as CallsPerMinute from AlphaVantageKeys;"; List <KeyDto> dtos = SQLUtilities.FromQuery <KeyDto>(keyQuery); keyAgents = dtos.Select(d => new AlphaVantageAgent.KeyAgent(parent, d.DailyCallMax, d.CallsPerMinute, d.ApiKey, d.DateLastUsed, d.DailyCallCount)) .ToList(); return(keyAgents); }
private void pollDatabase() { Console.WriteLine("Agent poll database start"); string symbolQuery = @"select s.Symbol,CompanyName,Industry,HistoricalLoadStatus,HourlyFullStatus,MaxTimestamp from StockSymbol s left join (select Symbol, cast(max(PriceDate) as datetime) + cast(max(PriceTime) as datetime) as MaxTimestamp from StockPrice sp group by Symbol) sp on s.Symbol = sp.Symbol where (HistoricalLoadStatus = 0 or HourlyFullStatus = 0 or exists (select 1 from Util_DateTimes dt where MaxTimestamp < dt.DateTimePoint and dt.DateTimePoint < getdate() ) ) and IsActive = 1 order by s.LoadPriority, s.Symbol;"; List <StockSymbol> symbols = SQLUtilities.FromQuery <StockSymbol>(symbolQuery); foreach (StockSymbol s in symbols) { if (!s.HistoricalLoadStatus) { lock (this.tasks) { ILoadTask newTask = new LoadSymbolPriceData(stockSymbol: s.Symbol, outputSize: OutputSize.Full, apiFunction: ApiFunction.Daily); this.tasks.Add(newTask); } } if (!s.HourlyFullStatus) { lock (this.tasks) { ILoadTask newTask = new LoadSymbolPriceData(stockSymbol: s.Symbol, outputSize: OutputSize.Full, apiFunction: ApiFunction.ThirtyMin); this.tasks.Add(newTask); } } //if ((s.UpdateTimestamp - DateTime.Now).TotalMinutes > 30) //{ // lock (this.tasks) // { // ILoadTask newTask = new LoadSymbolPriceData(stockSymbol: s.Symbol, // outputSize: OutputSize.Compact, // apiFunction: ApiFunction.ThirtyMin); // this.tasks.Add(new LoadSymbolPriceData(stockSymbol: s.Symbol, // outputSize: OutputSize.Compact, // apiFunction: ApiFunction.ThirtyMin)); // } //} } }