-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathrecommendationsBySymbol.ts
106 lines (91 loc) · 2.93 KB
/
recommendationsBySymbol.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { StaticDecode, Type } from "@sinclair/typebox";
import type {
ModuleOptions,
ModuleOptionsWithValidateFalse,
ModuleOptionsWithValidateTrue,
ModuleThis,
} from "../lib/moduleCommon.js";
import { YahooNumber } from "../lib/yahooFinanceTypes.js";
const RecommendationsBySymbolResponse = Type.Object(
{
recommendedSymbols: Type.Array(
Type.Object(
{
score: YahooNumber, // 0.1927
symbol: Type.String(), // "BMW.DE"
},
{
additionalProperties: Type.Any(),
},
),
),
symbol: Type.String(),
},
{
additionalProperties: Type.Any(),
},
);
const RecommendationsBySymbolResponseArray = Type.Array(
RecommendationsBySymbolResponse,
);
const RecommendationsBySymbolOptions = Type.Object({});
export type RecommendationsBySymbolResponse = StaticDecode<
typeof RecommendationsBySymbolResponse
>;
export type RecommendationsBySymbolOptions = StaticDecode<
typeof RecommendationsBySymbolOptions
>;
export type RecommendationsBySymbolResponseArray = StaticDecode<
typeof RecommendationsBySymbolResponseArray
>;
const queryOptionsDefaults: RecommendationsBySymbolOptions = {};
export default function recommendationsBySymbol(
this: ModuleThis,
query: string,
queryOptionsOverrides?: RecommendationsBySymbolOptions,
moduleOptions?: ModuleOptionsWithValidateTrue,
): Promise<RecommendationsBySymbolResponse>;
export default function recommendationsBySymbol(
this: ModuleThis,
query: string | string[],
queryOptionsOverrides?: RecommendationsBySymbolOptions,
moduleOptions?: ModuleOptionsWithValidateTrue,
): Promise<RecommendationsBySymbolResponseArray>;
export default function recommendationsBySymbol(
this: ModuleThis,
query: string | string[],
queryOptionsOverrides?: RecommendationsBySymbolOptions,
moduleOptions?: ModuleOptionsWithValidateFalse,
): Promise<any>;
export default function recommendationsBySymbol(
this: ModuleThis,
query: string | string[],
queryOptionsOverrides?: RecommendationsBySymbolOptions,
moduleOptions?: ModuleOptions,
): Promise<any> {
const symbols = typeof query === "string" ? query : query.join(",");
return this._moduleExec({
moduleName: "recommendationsBySymbol",
query: {
url:
"https://${YF_QUERY_HOST}/v6/finance/recommendationsbysymbol/" +
symbols,
schema: RecommendationsBySymbolOptions,
defaults: queryOptionsDefaults,
overrides: queryOptionsOverrides,
},
result: {
schema: RecommendationsBySymbolResponseArray,
transformWith(result: any) {
if (!result.finance)
throw new Error("Unexpected result: " + JSON.stringify(result));
return result.finance.result;
},
},
moduleOptions,
}).then((results: RecommendationsBySymbolResponseArray) => {
return typeof query === "string"
? (results[0] as RecommendationsBySymbolResponse)
: (results as RecommendationsBySymbolResponseArray);
});
}