public async Task TestTimeZone() { Security security = await YahooQuotes.GetAsync("C") ?? throw new ArgumentException(); string exchangeTimezoneName = security.ExchangeTimezoneName !; var tz = DateTimeZoneProviders.Tzdb.GetZoneOrNull(exchangeTimezoneName); Assert.Equal(tz, security.ExchangeTimezone); long?seconds = security.RegularMarketTimeSeconds; var instant = Instant.FromUnixTimeSeconds(seconds.GetValueOrDefault()); var zdt = instant.InZone(tz !); Assert.Equal(zdt, security.RegularMarketTime); }
public async Task Run(int number, HistoryFlags flags, string baseCurrency) { List <Symbol> symbols = GetSymbols(number); Console.WriteLine($"Loaded {symbols.Count} symbols."); Console.WriteLine($"Retrieving values..."); Stopwatch watch = new(); watch.Start(); Dictionary <string, Security?> securities = await YahooQuotes.GetAsync(symbols.Select(x => x.Name), flags, baseCurrency); watch.Stop(); int n = securities.Values.Select(x => x).NotNull().Count(); double s = watch.Elapsed.TotalSeconds; double rate = n / s; Logger.LogWarning($"Rate = {n}/{s} = {rate}Hz"); Analyze(securities); }
/* * [InlineData("C", "JPYCHF=X", 1)] * [InlineData("CHF=X", "", 1)] * [InlineData("CHF=X", "JPY=X", 0)] * [InlineData("CHF=X", "CHF=X", 0)] * [InlineData("USD=X", "USD=X", 2)] * [InlineData("CHF=X", "X", 0)] * [InlineData("CHF=X", "JPYCHF=X", 1)] * [InlineData("JPYCHF=X", "", 0)] * [InlineData("JPYCHF=X", "JPY=X", 1)] * [InlineData("JPYCHF=X", "JPYCHF=X", 1)] * [InlineData("JPYCHF=X", "X", 1)] */ public async Task Test01Arguments(string symbol, string baseSymbol, int error) { var task = MyYahooQuotes.GetAsync(symbol, HistoryFlags.PriceHistory, baseSymbol); if (error == 0) { var result = await task; Assert.True(result?.PriceHistoryBase.HasValue); } if (error == 1) { await Assert.ThrowsAsync <ArgumentException>(async() => await task); } if (error == 2) { var result = await task; Assert.True(result?.PriceHistoryBase.HasError); } }
public async Task NullAndEmptySymbolTest() { #pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. _ = await Assert.ThrowsAsync <ArgumentNullException>(async() => await YahooQuotes.GetAsync((string)null)); _ = await Assert.ThrowsAsync <ArgumentException>(async() => await YahooQuotes.GetAsync("")); _ = await YahooQuotes.GetAsync(Array.Empty <string>()); _ = await Assert.ThrowsAsync <ArgumentNullException>(async() => await YahooQuotes.GetAsync((string[])null)); _ = await Assert.ThrowsAsync <ArgumentNullException>(async() => await YahooQuotes.GetAsync(new string[] { null })); _ = await Assert.ThrowsAsync <ArgumentException>(async() => await YahooQuotes.GetAsync(new string[] { "" })); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. }