Skip to content

Commit

Permalink
fix(search): ETF/Fund types, ?shortname, more tests (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
gadicc committed Feb 12, 2021
1 parent 854f55e commit 28a9b03
Show file tree
Hide file tree
Showing 6 changed files with 392 additions and 28 deletions.
151 changes: 143 additions & 8 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4234,6 +4234,88 @@
],
"type": "object"
},
"SearchQuoteYahoo": {
"additionalProperties": false,
"properties": {
"exchange": {
"type": "string"
},
"index": {
"const": "quotes",
"type": "string"
},
"isYahooFinance": {
"const": true,
"type": "boolean"
},
"longname": {
"type": "string"
},
"score": {
"yahooFinanceType": "number"
},
"shortname": {
"type": "string"
},
"symbol": {
"type": "string"
}
},
"required": [
"symbol",
"isYahooFinance",
"exchange",
"index",
"score"
],
"type": "object"
},
"SearchQuoteYahooETF": {
"additionalProperties": false,
"properties": {
"exchange": {
"type": "string"
},
"index": {
"const": "quotes",
"type": "string"
},
"isYahooFinance": {
"const": true,
"type": "boolean"
},
"longname": {
"type": "string"
},
"quoteType": {
"const": "ETF",
"type": "string"
},
"score": {
"yahooFinanceType": "number"
},
"shortname": {
"type": "string"
},
"symbol": {
"type": "string"
},
"typeDisp": {
"const": "ETF",
"type": "string"
}
},
"required": [
"exchange",
"index",
"isYahooFinance",
"quoteType",
"score",
"symbol",
"typeDisp"
],
"type": "object"
},
"SearchQuoteYahooEquity": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -4271,13 +4353,58 @@
},
"required": [
"exchange",
"shortname",
"index",
"isYahooFinance",
"quoteType",
"score",
"symbol",
"typeDisp"
],
"type": "object"
},
"SearchQuoteYahooFund": {
"additionalProperties": false,
"properties": {
"exchange": {
"type": "string"
},
"index": {
"const": "quotes",
"type": "string"
},
"isYahooFinance": {
"const": true,
"type": "boolean"
},
"longname": {
"type": "string"
},
"quoteType": {
"const": "MUTUALFUND",
"type": "string"
},
"score": {
"yahooFinanceType": "number"
},
"shortname": {
"type": "string"
},
"symbol": {
"type": "string"
},
"typeDisp": {
"const": "Fund",
"type": "string"
}
},
"required": [
"exchange",
"index",
"isYahooFinance",
"quoteType",
"score",
"typeDisp",
"isYahooFinance"
"symbol",
"typeDisp"
],
"type": "object"
},
Expand All @@ -4295,6 +4422,9 @@
"const": true,
"type": "boolean"
},
"longname": {
"type": "string"
},
"quoteType": {
"const": "OPTION",
"type": "string"
Expand All @@ -4315,13 +4445,12 @@
},
"required": [
"exchange",
"shortname",
"quoteType",
"symbol",
"index",
"isYahooFinance",
"quoteType",
"score",
"typeDisp",
"isYahooFinance"
"symbol",
"typeDisp"
],
"type": "object"
},
Expand Down Expand Up @@ -4358,6 +4487,12 @@
{
"$ref": "#/definitions/SearchQuoteYahooOption"
},
{
"$ref": "#/definitions/SearchQuoteYahooETF"
},
{
"$ref": "#/definitions/SearchQuoteYahooFund"
},
{
"$ref": "#/definitions/SearchQuoteNonYahoo"
}
Expand Down
5 changes: 2 additions & 3 deletions src/modules/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import testYf from "../../tests/testYf";
const yf = testYf({ search });

const testSearches = [
"AAPL", // NMS (Nasdaq)
"OCDO.L", // LSE
"BABA", // NYSE
...testSymbols,
"Evolution Gaming Group", // STO
"Bayerische Motoren Werke AG", // GER
"NO0010123060", // has no shortname! (#31)
];

describe("search", () => {
Expand Down
42 changes: 25 additions & 17 deletions src/modules/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@ import type {
ModuleThis,
} from "../lib/moduleCommon";

export interface SearchQuoteYahooEquity {
exchange: string; // "NYQ"
shortname: string; // "Alibaba Group Holding Limited"
quoteType: "EQUITY"; // "EQUITY"
export interface SearchQuoteYahoo {
symbol: string; // "BABA"
index: "quotes"; // "quotes"
score: number; // 1111958.0
typeDisp: "Equity"; // "Equity"
longname?: string; // "Alibaba Group Holding Limited"
isYahooFinance: true; // true
}
export interface SearchQuoteYahooOption {
exchange: string; // "OPR"
shortname: string; // "AAPL Feb 2021 65.000 call"
quoteType: "OPTION"; // "EQUITY" TODO "EQUITY" | ???
symbol: string; // "AAPL210205C00065000"
exchange: string; // "NYQ"
shortname?: string; // "Alibaba Group Holding Limited"
longname?: string; // "Alibaba Group Holding Limited"
index: "quotes"; // "quotes"
score: number; // 1111958.0
typeDisp: "Option"; // "Option"
isYahooFinance: true; // true
}
export interface SearchQuoteYahooEquity extends SearchQuoteYahoo {
quoteType: "EQUITY";
typeDisp: "Equity";
}
export interface SearchQuoteYahooOption extends SearchQuoteYahoo {
quoteType: "OPTION";
typeDisp: "Option";
}
export interface SearchQuoteYahooETF extends SearchQuoteYahoo {
quoteType: "ETF";
typeDisp: "ETF"; // "Option"
}
export interface SearchQuoteYahooFund extends SearchQuoteYahoo {
quoteType: "MUTUALFUND";
typeDisp: "Fund";
}
export interface SearchQuoteNonYahoo {
index: string; // '78ddc07626ff4bbcae663e88514c23a0'
Expand All @@ -46,7 +50,11 @@ export interface SearchResult {
explains: Array<any>;
count: number;
quotes: Array<
SearchQuoteYahooEquity | SearchQuoteYahooOption | SearchQuoteNonYahoo
| SearchQuoteYahooEquity
| SearchQuoteYahooOption
| SearchQuoteYahooETF
| SearchQuoteYahooFund
| SearchQuoteNonYahoo
>;
news: Array<SearchNews>;
nav: Array<any>;
Expand Down
73 changes: 73 additions & 0 deletions tests/http/search-0P000071W8.TO.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"request": {
"url": "https://query2.finance.yahoo.com/v1/finance/search?lang=en-US&region=US&quotesCount=6&newsCount=4&enableFuzzyQuery=false&quotesQueryId=tss_match_phrase_query&multiQuoteQueryId=multi_quote_single_token_query&newsQueryId=news_cie_vespa&enableCb=true&enableNavLinks=true&enableEnhancedTrivialQuery=true&q=0P000071W8.TO"
},
"response": {
"ok": true,
"status": 200,
"statusText": "OK",
"headers": {
"content-type": [
"application/json"
],
"vary": [
"Origin,Origin,Accept-Encoding"
],
"cache-control": [
"public, max-age=120, stale-while-revalidate=180"
],
"y-rid": [
"am6je9pg2csuq"
],
"x-yahoo-request-id": [
"am6je9pg2csuq"
],
"x-request-id": [
"f5b79422-7f04-44e2-bc5b-3c523393ab70"
],
"content-encoding": [
"gzip"
],
"content-length": [
"609"
],
"x-envoy-upstream-service-time": [
"27"
],
"date": [
"Fri, 12 Feb 2021 12:26:02 GMT"
],
"server": [
"ATS"
],
"x-envoy-decorator-operation": [
"finance-search--mtls-production-ir2.finance-k8s.svc.yahoo.local:4080/*"
],
"age": [
"0"
],
"strict-transport-security": [
"max-age=15552000"
],
"referrer-policy": [
"no-referrer-when-downgrade"
],
"x-frame-options": [
"SAMEORIGIN"
],
"connection": [
"close"
],
"expect-ct": [
"max-age=31536000, report-uri=\"http://csp.yahoo.com/beacon/csp?src=yahoocom-expect-ct-report-only\""
],
"x-xss-protection": [
"1; mode=block"
],
"x-content-type-options": [
"nosniff"
]
},
"body": "{\"explains\":[],\"count\":6,\"quotes\":[{\"exchange\":\"TOR\",\"shortname\":\"TD Indiciel américain - e (C$)\",\"quoteType\":\"MUTUALFUND\",\"symbol\":\"0P000071W8.TO\",\"index\":\"quotes\",\"score\":2000100.0,\"typeDisp\":\"Fund\",\"longname\":\"TD U.S. Index Fund - e\",\"isYahooFinance\":true}],\"news\":[],\"nav\":[{\"navName\":\"How To\",\"navUrl\":\"http://finance.yahoo.com/tech/how-to\"}],\"lists\":[{\"slug\":\"most-added\",\"name\":\"Most Added to Watchlists\",\"index\":\"most-added\",\"score\":11.003144,\"type\":\"ALGO_WATCHLIST\",\"brandSlug\":\"yahoo-finance\",\"pfId\":\"most_added\"},{\"slug\":\"top-crypto-bets\",\"name\":\"Top Crypto Bets\",\"index\":\"top-crypto-bets\",\"score\":5.9393153,\"type\":\"ALGO_WATCHLIST\",\"brandSlug\":\"yahoo-finance\",\"pfId\":\"top_crypto_bets\"},{\"slug\":\"crypto-top-market-cap\",\"name\":\"Top Cryptos by Market Cap\",\"index\":\"crypto-top-market-cap\",\"score\":2.7857459,\"type\":\"ALGO_WATCHLIST\",\"brandSlug\":\"yahoo-finance\",\"pfId\":\"crypto_top_market_cap\"},{\"slug\":\"crypto-top-volume-24hr\",\"name\":\"Top Cryptos by Volume (all currencies, 24hr)\",\"index\":\"crypto-top-volume-24hr\",\"score\":2.4794414,\"type\":\"ALGO_WATCHLIST\",\"brandSlug\":\"yahoo-finance\",\"pfId\":\"crypto_top_volume_24hr\"}],\"researchReports\":[],\"totalTime\":25,\"timeTakenForQuotes\":413,\"timeTakenForNews\":700,\"timeTakenForAlgowatchlist\":400,\"timeTakenForPredefinedScreener\":400,\"timeTakenForCrunchbase\":400,\"timeTakenForNav\":400,\"timeTakenForResearchReports\":0}"
}
}
Loading

0 comments on commit 28a9b03

Please sign in to comment.