-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.ts
More file actions
109 lines (89 loc) · 3.68 KB
/
api.ts
File metadata and controls
109 lines (89 loc) · 3.68 KB
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
107
108
109
import { WordFrequency } from '@ts/Interfaces';
import { StockCountryKey } from '@ts/StockCountry';
import { enableMock, fetchData } from '../common/base';
import {
fetchChartMock,
fetchKeywordsMock,
fetchPopularStocksMock,
fetchRelevantMock,
fetchScoreCardMock,
fetchScoreMock,
fetchSearchSymbolNameMock,
fetchSearchWordCloudMock,
} from './mock';
import {
MonthlyAverageResponse,
PERIOD_CODE,
PopularStocks,
SectorAverageResponse,
SectorPercentileResponse,
StockDetailInfo,
} from './types';
export const fetchScore = async (id: number, country: string) => {
if (enableMock) return fetchScoreMock;
return fetchData(`/${id}/score/${country}`);
};
export const fetchRelevant = async (id: number) => {
if (enableMock) return fetchRelevantMock;
return fetchData(`/stock/${id}/relevant`);
};
export const fetchHotStocks = async (country: string) => {
return fetchData(`/stock/hot/${country}`);
};
export const fetchRisingStocks = async (country: string) => {
if (enableMock) return fetchScoreCardMock;
return fetchData(`/stock/rising/${country}`);
};
export const fetchDescentStocks = async (country: string) => {
if (enableMock) return fetchScoreCardMock;
return fetchData(`/stock/descent/${country}`);
};
export const fetchSearchSymbolName = (symbolname: string, country: StockCountryKey): Promise<StockDetailInfo> => {
if (enableMock) return Promise.resolve(fetchSearchSymbolNameMock);
return fetchData(`/stock/search/${symbolname}/${country}`);
};
export const fetchStockInfo = (stockId: number, country: StockCountryKey) => {
return fetchData(`/stock/${stockId}/info/${country}`);
};
export const fetchStockTable = (category: string, country: string) => {
return fetchData(`/stock/category/${category}/${country}`);
};
export const fetchStockSummary = (symbol: string, country: StockCountryKey) => {
return fetchData(`/stock/summary/${symbol}/${country}`);
};
export const fetchSearchWordCloud = (symbol: string, country: string): Promise<WordFrequency[]> => {
if (enableMock) return Promise.resolve(fetchSearchWordCloudMock);
return fetchData(`/wordcloud/${symbol}/${country}`);
};
export const fetchStockChart = async (id: number, periodCode: PERIOD_CODE, startDate: string, endDate: string) => {
if (enableMock) return fetchChartMock;
return fetchData(`/stock/${id}/chart/{country}?periodCode=${periodCode}&startDate=${startDate}&endDate=${endDate}`);
};
export const fetchAutoComplete = (name: string) => {
return fetchData(`/stock/autocomplete?keyword=${name}`);
};
export const fetchPopularStocks = (): Promise<PopularStocks[]> => {
if (enableMock) return Promise.resolve(fetchPopularStocksMock as PopularStocks[]);
return fetchData(`/stock/rankings/hot`);
};
// keyword
export const fetchSearchKeyword = (keywordName: string) => {
return fetchData(`/keyword/${keywordName}/stocks`);
};
export const fetchKeywordRankings = (): Promise<string[]> => {
return fetchData('/keyword/rankings');
};
export const fetchPopularKeywords = (country: string): Promise<string[]> => {
if (enableMock) return Promise.resolve(fetchKeywordsMock);
return fetchData(`/keyword/popular/${country}`);
};
export const fetchSectorAverage = (country: string, sector: string): Promise<SectorAverageResponse> => {
return fetchData(`/stock/sector/average/${country}/${sector}`);
};
export const fetchSectorPercentile = (stockId: number): Promise<SectorPercentileResponse> => {
return fetchData(`/stock/${stockId}/sector/percentile`);
};
export const fetchMonthlyAverage = (stockId: number, yearMonth?: string): Promise<MonthlyAverageResponse> => {
const queryParam = yearMonth ? `?yearMonth=${yearMonth}` : '';
return fetchData(`/stock/${stockId}/average/month${queryParam}`);
};