public IList <IApiResource> GetApiResources(DataTypeConfig dataType, string ticker, IComparablePeriod from, IComparablePeriod to, bool isConfigureAwait = true, bool useCache = true) { UpdateApiKeyIfNeeded(); if (from.CompareTo(to) > 0) { throw new ArgumentException($"from={from} is more than to={to}"); } var endOfOndemandPeriod = taskHelper.FindEndOfOndemandPeriod(dataType, ticker, PeriodRange <IComparablePeriod> .Create(from, to), config.IsOndemandEndpointEnabled, isConfigureAwait, useCache); // use fixed tier from all range if (endOfOndemandPeriod is null) { var parameter = TickerPeriodRangeParameter.Create(ticker, from, to); var json = client.GetRange(dataType, parameter, false, isConfigureAwait, useCache); return(parser.ParseRange(dataType, json)); } else { var ondemandParameter = TickerPeriodRangeParameter.Create(ticker, from, endOfOndemandPeriod); var fixedParameter = TickerPeriodRangeParameter.Create(ticker, endOfOndemandPeriod.Next(), to); var ondemandTierJson = client.GetRange(dataType, ondemandParameter, true, isConfigureAwait, useCache); var fixedTierJson = client.GetRange(dataType, fixedParameter, false, isConfigureAwait, useCache); var ondemandResources = parser.ParseRange(dataType, ondemandTierJson); var fixedTierResource = parser.ParseRange(dataType, fixedTierJson); return(ondemandResources.Concat(fixedTierResource).ToList()); } }
public void GetQuarterRangeTest() { var client = new BuffettCodeApiV2Client(mockApiCore); var from = FiscalQuarterPeriod.Create(2019, 4); var to = FiscalQuarterPeriod.Create(2019, 4); var parameter = TickerPeriodRangeParameter.Create("6501", from, to); Assert.IsNotNull(client.GetQuarterRange(parameter, false, false)); }
public void GetRangeTest() { var client = new BuffettCodeApiV2Client(mockApiCore); var ticker = "2345"; var day = DayPeriod.Create(2021, 2, 1); var fyFq = FiscalQuarterPeriod.Create(2019, 4); Assert.IsNotNull(client.GetRange(DataTypeConfig.Quarter, TickerPeriodRangeParameter.Create(ticker, fyFq, fyFq), false, true, false)); Assert.ThrowsException <NotSupportedDataTypeException>(() => client.GetRange(DataTypeConfig.Daily, TickerPeriodRangeParameter.Create(ticker, day, day), false, true, false)); }
public void ToApiV2ParametersTest() { var ticker = "1234"; var from = FiscalQuarterPeriod.Create(2020, 1); var to = FiscalQuarterPeriod.Create(2020, 2); var parameter = TickerPeriodRangeParameter.Create(ticker, from, to).ToApiV2Parameters(); Assert.AreEqual(ticker, parameter["tickers"]); Assert.AreEqual(from.ToString(), parameter["from"]); Assert.AreEqual(to.ToString(), parameter["to"]); }
public void CreateGetQuarterRangeRequestTest() { // ok case var ticker = "6501"; var fromStr = "2020Q1"; var toStr = "2022Q4"; var from = FiscalQuarterPeriod.Parse(fromStr); var to = FiscalQuarterPeriod.Parse(toStr); var parameter = TickerPeriodRangeParameter.Create(ticker, from, to); var request = BuffettCodeApiV3RequestCreator.CreateGetQuarterRangeRequest(parameter); Assert.AreEqual(request.EndPoint, BuffettCodeApiV3Config.ENDPOINT_BULK_QUARTER); Assert.AreEqual(ticker, request.Parameters["ticker"]); Assert.AreEqual(fromStr, request.Parameters["from"]); Assert.AreEqual(toStr, request.Parameters["to"]); }