Skip to content

Commit

Permalink
fix(quote): don't pulle Quote with QuoteNone (fixes #417)
Browse files Browse the repository at this point in the history
Completely remove the QuoteNone type, and filter out
quoteType=="NONE" before passing network results to validation.
  • Loading branch information
gadicc committed Feb 26, 2022
1 parent 96283e4 commit 5178c78
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 94 deletions.
48 changes: 0 additions & 48 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -3783,9 +3738,6 @@
{
"$ref": "#/definitions/QuoteMutualfund"
},
{
"$ref": "#/definitions/QuoteNone"
},
{
"$ref": "#/definitions/QuoteOption"
}
Expand Down
78 changes: 32 additions & 46 deletions src/modules/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -179,7 +167,6 @@ export type Quote =
| QuoteEquity
| QuoteIndex
| QuoteMutualfund
| QuoteNone
| QuoteOption;

export type QuoteField = keyof Quote;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5178c78

Please sign in to comment.