diff --git a/schema.json b/schema.json index f6c2345b..44c1c8b8 100644 --- a/schema.json +++ b/schema.json @@ -3416,51 +3416,6 @@ ], "additionalProperties": false }, - "QuoteNone": { - "type": "object", - "properties": { - "quoteType": { - "type": "string", - "const": "NONE" - }, - "language": { - "type": "string" - }, - "region": { - "type": "string" - }, - "triggerable": { - "type": "boolean" - }, - "customPriceAlertConfidence": { - "type": "string" - }, - "tradeable": { - "type": "boolean" - }, - "messageBoardId": { - "type": "string" - }, - "esgPopulated": { - "type": "boolean" - }, - "symbol": { - "type": "string" - } - }, - "required": [ - "quoteType", - "language", - "region", - "triggerable", - "customPriceAlertConfidence", - "tradeable", - "messageBoardId", - "esgPopulated", - "symbol" - ], - "additionalProperties": false - }, "QuoteMutualfund": { "type": "object", "properties": { @@ -3783,9 +3738,6 @@ { "$ref": "#/definitions/QuoteMutualfund" }, - { - "$ref": "#/definitions/QuoteNone" - }, { "$ref": "#/definitions/QuoteOption" } diff --git a/src/modules/quote.ts b/src/modules/quote.ts index 53fbdf6c..197b9498 100644 --- a/src/modules/quote.ts +++ b/src/modules/quote.ts @@ -156,18 +156,6 @@ export interface QuoteOption extends QuoteBase { underlyingSymbol: string; } -export interface QuoteNone { - quoteType: "NONE"; - language: string; - region: string; - triggerable: boolean; - customPriceAlertConfidence: string; - tradeable: boolean; - messageBoardId: string; - esgPopulated: boolean; - symbol: string; -} - export interface QuoteMutualfund extends QuoteBase { quoteType: "MUTUALFUND"; } @@ -179,7 +167,6 @@ export type Quote = | QuoteEquity | QuoteIndex | QuoteMutualfund - | QuoteNone | QuoteOption; export type QuoteField = keyof Quote; @@ -255,45 +242,44 @@ export default async function quote( const symbols = typeof query === "string" ? query : query.join(","); const returnAs = queryOptionsOverrides && queryOptionsOverrides.return; - const results: Quote[] = ( - await this._moduleExec({ - moduleName: "quote", - - query: { - url: "https://query2.finance.yahoo.com/v7/finance/quote", - schemaKey: "#/definitions/QuoteOptions", - defaults: queryOptionsDefaults, - runtime: { symbols }, - overrides: queryOptionsOverrides, - transformWith(queryOptions: QuoteOptions) { - // Options validation ensures this is a string[] - if (queryOptions.fields) queryOptions.fields.join(","); - - // Don't pass this on to Yahoo - delete queryOptions.return; - - return queryOptions; - }, + const results: Quote[] = await this._moduleExec({ + moduleName: "quote", + + query: { + url: "https://query2.finance.yahoo.com/v7/finance/quote", + schemaKey: "#/definitions/QuoteOptions", + defaults: queryOptionsDefaults, + runtime: { symbols }, + overrides: queryOptionsOverrides, + transformWith(queryOptions: QuoteOptions) { + // Options validation ensures this is a string[] + if (queryOptions.fields) queryOptions.fields.join(","); + + // Don't pass this on to Yahoo + delete queryOptions.return; + + return queryOptions; }, + }, + + result: { + schemaKey: "#/definitions/QuoteResponseArray", + transformWith(rawResult: any) { + let results = rawResult?.quoteResponse?.result; - result: { - schemaKey: "#/definitions/QuoteResponseArray", - transformWith(rawResult: any) { - const results = rawResult?.quoteResponse?.result; + if (!results || !Array.isArray(results)) + throw new Error("Unexpected result: " + JSON.stringify(rawResult)); - if (!results) - throw new Error("Unexpected result: " + JSON.stringify(rawResult)); + // Filter out quoteType==='NONE' + // So that delisted stocks will be undefined just like symbol-not-found + results = results.filter((quote: any) => quote?.quoteType !== "NONE"); - return results; - }, + return results; }, + }, - moduleOptions, - }) - ) - // Filter out quoteType==='NONE' - // So that delisted stocks will be undefined just like symbol-not-found - .filter((quote: Quote) => quote.quoteType !== "NONE"); + moduleOptions, + }); if (returnAs) { switch (returnAs) {