private SortableList <IFavorite> TryLodFromDatabase(string historyDateKey) { using (Database database = DatabaseConnections.CreateInstance()) { HistoryInterval interval = HistoryIntervals.GetIntervalByName(historyDateKey); // store holds dates in UTC var favoriteIds = database.GetFavoritesHistoryByDate(interval.From, interval.To).ToList(); IEnumerable <DbFavorite> intervalFavorites = this.favorites.Cast <DbFavorite>().Where(favorite => favoriteIds.Contains(favorite.Id)); return(Data.Favorites.OrderByDefaultSorting(intervalFavorites)); } }
private string IntervalToString(HistoryInterval interval) { switch (interval) { case HistoryInterval.Daily: return("1d"); case HistoryInterval.Weekly: return("1w"); case HistoryInterval.Monthly: return("1m"); default: throw new NotImplementedException($"Interval '{interval}' does not exist"); } }
// Request string for HistoryType.IntervalTimeframe public string GetRequestIntervalTimeframe(string symbol, HistoryIntervalType itype, HistoryInterval interval, string beginDateTime, string endDateTime, HistoryDataDirection direction = HistoryDataDirection.Forward, string datapointsPerSend = "", string maxDatapoints = "", string beginFilterTime = "", string endFilterTime = "") { return GetRequestIntervalTimeframe(symbol, itype, ((int)interval).ToString(), beginDateTime, endDateTime, direction, datapointsPerSend, maxDatapoints, beginFilterTime, endFilterTime); }
public void HistoryIntervalTimeframe(string symbol, HistoryIntervalType itype, HistoryInterval interval, string beginDateTime = null, string endDateTime = null, HistoryDataDirection direction = HistoryDataDirection.Forward, string datapointsPerSend = "", string maxDatapoints = "", string beginFilterTime = "", string endFilterTime = "") { string sInterval = ((int)interval).ToString(); HistoryIntervalTimeframe(symbol, itype, sInterval, beginDateTime, endDateTime, direction, datapointsPerSend, maxDatapoints, beginFilterTime, endFilterTime); }
public void HistoryFuturesIntervalTimeframe(string rootSymbol, HistoryIntervalType itype, HistoryInterval interval, string beginDateTime = null, string endDateTime = null, HistoryDataDirection direction = HistoryDataDirection.Forward, string datapointsPerSend = "", string maxDatapoints = "", string beginFilterTime = "", string endFilterTime = "") { m_filename = Folders.df_path(GFile.GetDfFuturesFilename(rootSymbol, (int)interval)); m_outfile = null; int addMonthsToEnd = 6; beginDateTime = beginDateTime ?? EARLIEST_DATE; endDateTime = endDateTime ?? DateTime.Now.AddMonths(addMonthsToEnd).ToString("yyyyMMdd"); var mcList = GetMonthCodeList(beginDateTime, endDateTime); string sInterval = ((int)interval).ToString(); foreach (var mYY in mcList) { m_symbol = rootSymbol + mYY; // use mYY and the mYY from 6 months prior to calculate a begin and end date for contract historical data string mYYplus1 = AddMonths(mYY, 1); string mYYminus6 = AddMonths(mYY, -6); string dt1 = GetDateTimeMYY(mYYminus6).ToYYYYMMDD(); string dt2 = GetDateTimeMYY(mYYplus1).ToYYYYMMDD(); HistoryIntervalTimeframe(m_symbol, itype, sInterval, dt1, dt2, direction, datapointsPerSend, maxDatapoints, beginFilterTime, endFilterTime); } if (m_outfile != null) { m_outfile.Close(); Console.WriteLine("\nOutput to file: {0}\n", m_filename); } }
public void HistoryContractIntervalTimeframe(string symbol, HistoryIntervalType itype, HistoryInterval interval, string beginDateTime = null, string endDateTime = null, HistoryDataDirection direction = HistoryDataDirection.Forward, string datapointsPerSend = "", string maxDatapoints = "", string beginFilterTime = "", string endFilterTime = "") { m_filename = Folders.df_path(GFile.GetDfContractFilename(symbol, (int)interval)); m_outfile = null; beginDateTime = beginDateTime ?? EARLIEST_DATE; endDateTime = endDateTime ?? DateTime.Now.AddMonths(1).ToString("yyyyMMdd"); string sInterval = ((int)interval).ToString(); m_symbol = symbol; HistoryIntervalTimeframe(m_symbol, itype, sInterval, beginDateTime, endDateTime, direction, datapointsPerSend, maxDatapoints, beginFilterTime, endFilterTime); if (m_outfile != null) { m_outfile.Close(); Console.WriteLine("\nOutput to file: {0}\n", m_filename); } }
public async Task <IApiResponse <IReadOnlyList <SplitResult> > > GetSplitsAsync(string symbol, Instant start, Instant end, HistoryInterval interval = HistoryInterval.Daily, CancellationToken cancellationToken = default) { if (start >= end) { return(ApiResponse.FromError <IReadOnlyList <SplitResult> >(null, "Start date needs to happen before end date")); } var apiResult = await GetData <SplitResult>(symbol, start, end, interval, cancellationToken); logger.LogDebug("{Svc}::GetSplitsAsync completed in {ResponseTime} with status code {StatusCode} reason {ReasonPhrase}", nameof(HistoryService), apiResult.Metadata.ResponseTime, apiResult.Metadata.StatusCode, apiResult.Metadata.ReasonPhrase); if (apiResult.HasError) { return(ApiResponse.FromError <IReadOnlyList <SplitResult> >(apiResult.Metadata, apiResult.Error)); } var results = (IReadOnlyList <SplitResult>)(apiResult.Data .Where(d => d.Split.Before != 0 && d.Split.After != 0) .OrderByDescending(d => d.Date) .ToList()); logger.LogInformation("HistoryService::GetSplitsAsync returns SUCCES - found {count} results", results.Count); return(ApiResponse.FromSucces(apiResult.Metadata, results)); }
private async Task <IApiResponse <IEnumerable <T> > > GetData <T>(string symbol, Instant start, Instant end, HistoryInterval interval, CancellationToken cancellationToken) where T : class, IHistoryItem { const string url = "v7/finance/download/[symbol]"; var qsb = new QueryStringBuilder(); qsb.Add("interval", IntervalToString(interval)); qsb.Add("period1", start.ToUnixTimeSeconds()); qsb.Add("period2", end.ToUnixTimeSeconds()); qsb.Add("events", GetEventTypeFromHistoryItem <T>()); var nvc = new NameValueCollection() { { "symbol", symbol } }; return(await client.ExecuteCsvAsync <T>(url, nvc, qsb, cancellationToken)); }