From abd2777ee017a7dd77d720a728e7d6c05cc8d586 Mon Sep 17 00:00:00 2001 From: Robert Fraatz Date: Mon, 4 Sep 2023 00:55:35 +0200 Subject: [PATCH] fix module chart: fixes validation error in the case where null values are returned --- src/modules/chart.spec.ts | 14 ++++++++++++++ src/modules/chart.ts | 24 ++++++++++++------------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/modules/chart.spec.ts b/src/modules/chart.spec.ts index f6beb5f7..918ff36a 100644 --- a/src/modules/chart.spec.ts +++ b/src/modules/chart.spec.ts @@ -34,6 +34,20 @@ describe("chart", () => { ); }); + it("passes validation if some results are null", async () => { + await yf.chart( + "WSU.DE", + { + period1: "2023-08-04", // This was yielding a FailedYahooValidationError since + period2: "2023-08-09", // there are no results on the 2023-08-07 + return: "object", // native Yahoo return format, first validation step. + }, + { + devel: `chart-WSU.DE-2023-08-04-to-2023-08-09.json`, + } + ); + }); + it("throws if period1,period2 are the same", async () => { await expect( yf.chart("TSLA", { period1: "2022-02-22", period2: "2022-02-22" }) diff --git a/src/modules/chart.ts b/src/modules/chart.ts index 52dfedc2..33541cda 100644 --- a/src/modules/chart.ts +++ b/src/modules/chart.ts @@ -24,12 +24,12 @@ export interface ChartResultArray { export interface ChartResultArrayQuote { [key: string]: any; date: Date; - high: number; - low: number; - open: number; - close: number; - volume: number; - adjclose?: number; + high: number|null; + low: number|null; + open: number|null; + close: number|null; + volume: number|null; + adjclose?: number|null; } export interface ChartMeta { @@ -117,16 +117,16 @@ export interface ChartIndicatorsObject { export interface ChartIndicatorQuote { [key: string]: any; - high: Array; - low: Array; - open: Array; - close: Array; - volume: Array; + high: Array; + low: Array; + open: Array; + close: Array; + volume: Array; } export interface ChartIndicatorAdjclose { [key: string]: any; - adjclose?: Array; // Missing in e.g. "APS.AX" + adjclose?: Array; // Missing in e.g. "APS.AX" } export interface ChartOptions {