@fugle/node-twstock 2.2.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1837 -0
- package/lib/enums/exchange.enum.d.ts +5 -0
- package/lib/enums/exchange.enum.js +9 -0
- package/lib/enums/futopt.enum.d.ts +34 -0
- package/lib/enums/futopt.enum.js +38 -0
- package/lib/enums/index.d.ts +6 -0
- package/lib/enums/index.enum.d.ts +67 -0
- package/lib/enums/index.enum.js +71 -0
- package/lib/enums/index.js +22 -0
- package/lib/enums/industry.enum.d.ts +40 -0
- package/lib/enums/industry.enum.js +44 -0
- package/lib/enums/market.enum.d.ts +5 -0
- package/lib/enums/market.enum.js +9 -0
- package/lib/enums/scraper.enum.d.ts +10 -0
- package/lib/enums/scraper.enum.js +14 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +18 -0
- package/lib/interfaces/futopt-exchange-rates.interface.d.ts +13 -0
- package/lib/interfaces/futopt-exchange-rates.interface.js +2 -0
- package/lib/interfaces/futopt-historical.interface.d.ts +23 -0
- package/lib/interfaces/futopt-historical.interface.js +2 -0
- package/lib/interfaces/futopt-institutional.interface.d.ts +21 -0
- package/lib/interfaces/futopt-institutional.interface.js +2 -0
- package/lib/interfaces/futopt-large-traders.interface.d.ts +16 -0
- package/lib/interfaces/futopt-large-traders.interface.js +2 -0
- package/lib/interfaces/futopt-mxf-retail-position.interface.d.ts +7 -0
- package/lib/interfaces/futopt-mxf-retail-position.interface.js +2 -0
- package/lib/interfaces/futopt-quote.interface.d.ts +31 -0
- package/lib/interfaces/futopt-quote.interface.js +2 -0
- package/lib/interfaces/futopt-tmf-retail-position.interface.d.ts +7 -0
- package/lib/interfaces/futopt-tmf-retail-position.interface.js +2 -0
- package/lib/interfaces/futopt-txo-put-call-ratio.interface.d.ts +9 -0
- package/lib/interfaces/futopt-txo-put-call-ratio.interface.js +2 -0
- package/lib/interfaces/futopt.interface.d.ts +7 -0
- package/lib/interfaces/futopt.interface.js +2 -0
- package/lib/interfaces/index-historical.interface.d.ts +11 -0
- package/lib/interfaces/index-historical.interface.js +2 -0
- package/lib/interfaces/index-quote.interface.d.ts +13 -0
- package/lib/interfaces/index-quote.interface.js +2 -0
- package/lib/interfaces/index-trades.interface.d.ts +9 -0
- package/lib/interfaces/index-trades.interface.js +2 -0
- package/lib/interfaces/index.d.ts +37 -0
- package/lib/interfaces/index.js +53 -0
- package/lib/interfaces/market-breadth.interface.d.ts +11 -0
- package/lib/interfaces/market-breadth.interface.js +2 -0
- package/lib/interfaces/market-institutional.interface.d.ts +10 -0
- package/lib/interfaces/market-institutional.interface.js +2 -0
- package/lib/interfaces/market-margin-trades.interface.d.ts +19 -0
- package/lib/interfaces/market-margin-trades.interface.js +2 -0
- package/lib/interfaces/market-trades.interface.d.ts +7 -0
- package/lib/interfaces/market-trades.interface.js +2 -0
- package/lib/interfaces/rate-limit-options.interface.d.ts +4 -0
- package/lib/interfaces/rate-limit-options.interface.js +2 -0
- package/lib/interfaces/stock-capital-reductions.interface.d.ts +23 -0
- package/lib/interfaces/stock-capital-reductions.interface.js +2 -0
- package/lib/interfaces/stock-dividends.interface.d.ts +27 -0
- package/lib/interfaces/stock-dividends.interface.js +2 -0
- package/lib/interfaces/stock-eps.interface.d.ts +8 -0
- package/lib/interfaces/stock-eps.interface.js +2 -0
- package/lib/interfaces/stock-fini-holdings.interface.d.ts +12 -0
- package/lib/interfaces/stock-fini-holdings.interface.js +2 -0
- package/lib/interfaces/stock-futopt.interface.d.ts +8 -0
- package/lib/interfaces/stock-futopt.interface.js +2 -0
- package/lib/interfaces/stock-historical.interface.d.ts +14 -0
- package/lib/interfaces/stock-historical.interface.js +2 -0
- package/lib/interfaces/stock-institutional.interface.d.ts +12 -0
- package/lib/interfaces/stock-institutional.interface.js +2 -0
- package/lib/interfaces/stock-margin-trades.interface.d.ts +20 -0
- package/lib/interfaces/stock-margin-trades.interface.js +2 -0
- package/lib/interfaces/stock-quote.interface.d.ts +19 -0
- package/lib/interfaces/stock-quote.interface.js +2 -0
- package/lib/interfaces/stock-revenue.interface.d.ts +8 -0
- package/lib/interfaces/stock-revenue.interface.js +2 -0
- package/lib/interfaces/stock-shareholders.interface.d.ts +11 -0
- package/lib/interfaces/stock-shareholders.interface.js +2 -0
- package/lib/interfaces/stock-short-sales.interface.d.ts +19 -0
- package/lib/interfaces/stock-short-sales.interface.js +2 -0
- package/lib/interfaces/stock-splits.interface.d.ts +12 -0
- package/lib/interfaces/stock-splits.interface.js +2 -0
- package/lib/interfaces/stock-values.interface.d.ts +10 -0
- package/lib/interfaces/stock-values.interface.js +2 -0
- package/lib/interfaces/stock.interface.d.ts +8 -0
- package/lib/interfaces/stock.interface.js +2 -0
- package/lib/interfaces/stocks-capital-reduction-announcement.interface.d.ts +19 -0
- package/lib/interfaces/stocks-capital-reduction-announcement.interface.js +2 -0
- package/lib/interfaces/stocks-dividends-announcement.interface.d.ts +21 -0
- package/lib/interfaces/stocks-dividends-announcement.interface.js +2 -0
- package/lib/interfaces/stocks-etf-split-announcement.interface.d.ts +11 -0
- package/lib/interfaces/stocks-etf-split-announcement.interface.js +2 -0
- package/lib/interfaces/stocks-listing-application.interface.d.ts +16 -0
- package/lib/interfaces/stocks-listing-application.interface.js +2 -0
- package/lib/interfaces/stocks-split-announcement.interface.d.ts +11 -0
- package/lib/interfaces/stocks-split-announcement.interface.js +2 -0
- package/lib/interfaces/ticker.interface.d.ts +10 -0
- package/lib/interfaces/ticker.interface.js +2 -0
- package/lib/scrapers/index.d.ts +10 -0
- package/lib/scrapers/index.js +26 -0
- package/lib/scrapers/isin-scraper.d.ts +13 -0
- package/lib/scrapers/isin-scraper.js +76 -0
- package/lib/scrapers/mis-taifex-scraper.d.ts +17 -0
- package/lib/scrapers/mis-taifex-scraper.js +126 -0
- package/lib/scrapers/mis-twse-scraper.d.ts +15 -0
- package/lib/scrapers/mis-twse-scraper.js +97 -0
- package/lib/scrapers/mops-scraper.d.ts +17 -0
- package/lib/scrapers/mops-scraper.js +64 -0
- package/lib/scrapers/scraper-factory.d.ts +25 -0
- package/lib/scrapers/scraper-factory.js +62 -0
- package/lib/scrapers/scraper.d.ts +6 -0
- package/lib/scrapers/scraper.js +20 -0
- package/lib/scrapers/taifex-scraper.d.ts +44 -0
- package/lib/scrapers/taifex-scraper.js +406 -0
- package/lib/scrapers/tdcc-scraper.d.ts +11 -0
- package/lib/scrapers/tdcc-scraper.js +82 -0
- package/lib/scrapers/tpex-scraper.d.ts +95 -0
- package/lib/scrapers/tpex-scraper.js +786 -0
- package/lib/scrapers/twse-scraper.d.ts +110 -0
- package/lib/scrapers/twse-scraper.js +967 -0
- package/lib/twstock.d.ts +229 -0
- package/lib/twstock.js +507 -0
- package/lib/utils/as-exchange.util.d.ts +2 -0
- package/lib/utils/as-exchange.util.js +15 -0
- package/lib/utils/as-index.util.d.ts +1 -0
- package/lib/utils/as-index.util.js +178 -0
- package/lib/utils/as-industry.util.d.ts +2 -0
- package/lib/utils/as-industry.util.js +49 -0
- package/lib/utils/date-converter.util.d.ts +47 -0
- package/lib/utils/date-converter.util.js +113 -0
- package/lib/utils/html-cleaner.util.d.ts +29 -0
- package/lib/utils/html-cleaner.util.js +45 -0
- package/lib/utils/index.d.ts +7 -0
- package/lib/utils/index.js +23 -0
- package/lib/utils/is-warrant.util.d.ts +1 -0
- package/lib/utils/is-warrant.util.js +25 -0
- package/lib/utils/parse-numeric.util.d.ts +21 -0
- package/lib/utils/parse-numeric.util.js +58 -0
- package/package.json +70 -0
package/lib/twstock.js
ADDED
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.TwStock = void 0;
|
|
15
|
+
const lodash_1 = require("lodash");
|
|
16
|
+
const scrapers_1 = require("./scrapers");
|
|
17
|
+
const enums_1 = require("./enums");
|
|
18
|
+
class TwStock {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this._stocks = new Map();
|
|
21
|
+
this._indices = new Map();
|
|
22
|
+
this._futopt = new Map();
|
|
23
|
+
this._scraper = new scrapers_1.ScraperFactory(options);
|
|
24
|
+
}
|
|
25
|
+
get stocks() {
|
|
26
|
+
return {
|
|
27
|
+
list: this.fetchStocksList.bind(this),
|
|
28
|
+
quote: this.fetchStocksQuote.bind(this),
|
|
29
|
+
historical: this.fetchStocksHistorical.bind(this),
|
|
30
|
+
institutional: this.fetchStocksInstitutional.bind(this),
|
|
31
|
+
values: this.fetchStocksValues.bind(this),
|
|
32
|
+
finiHoldings: this.fetchStocksFiniHoldings.bind(this),
|
|
33
|
+
marginTrades: this.fetchStocksMarginTrades.bind(this),
|
|
34
|
+
shortSales: this.fetchStocksShortSales.bind(this),
|
|
35
|
+
shareholders: this.fetchStocksShareholders.bind(this),
|
|
36
|
+
eps: this.fetchStocksEps.bind(this),
|
|
37
|
+
revenue: this.fetchStocksRevenue.bind(this),
|
|
38
|
+
dividends: this.fetchStocksDividends.bind(this),
|
|
39
|
+
dividendsAnnouncement: this.fetchStocksDividendsAnnouncement.bind(this),
|
|
40
|
+
capitalReductions: this.fetchStocksCapitalReductions.bind(this),
|
|
41
|
+
capitalReductionAnnouncement: this.fetchStocksCapitalReductionAnnouncement.bind(this),
|
|
42
|
+
splits: this.fetchStocksSplits.bind(this),
|
|
43
|
+
splitAnnouncement: this.fetchStocksSplitAnnouncement.bind(this),
|
|
44
|
+
etfSplits: this.fetchStocksEtfSplits.bind(this),
|
|
45
|
+
etfSplitAnnouncement: this.fetchStocksEtfSplitAnnouncement.bind(this),
|
|
46
|
+
listingApplicants: this.fetchStocksListingApplicants.bind(this),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
get indices() {
|
|
50
|
+
return {
|
|
51
|
+
list: this.getIndicesList.bind(this),
|
|
52
|
+
quote: this.getIndicesQuote.bind(this),
|
|
53
|
+
historical: this.getIndicesHistorical.bind(this),
|
|
54
|
+
trades: this.getIndicesTrades.bind(this),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
get market() {
|
|
58
|
+
return {
|
|
59
|
+
trades: this.getMarketTrades.bind(this),
|
|
60
|
+
breadth: this.getMarketBreadth.bind(this),
|
|
61
|
+
institutional: this.getMarketInstitutional.bind(this),
|
|
62
|
+
marginTrades: this.getMarketMarginTrades.bind(this),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
get futopt() {
|
|
66
|
+
return {
|
|
67
|
+
list: this.getFutOptList.bind(this),
|
|
68
|
+
quote: this.getFutOptQuote.bind(this),
|
|
69
|
+
historical: this.getFutOptHistorical.bind(this),
|
|
70
|
+
institutional: this.getFutOptInstitutional.bind(this),
|
|
71
|
+
largeTraders: this.getFutOptLargeTraders.bind(this),
|
|
72
|
+
mxfRetailPosition: this.getFutOptMxfRetailPosition.bind(this),
|
|
73
|
+
tmfRetailPosition: this.getFutOptTmfRetailPosition.bind(this),
|
|
74
|
+
txoPutCallRatio: this.getFutOptTxoPutCallRatio.bind(this),
|
|
75
|
+
exchangeRates: this.getFutOptExchangeRates.bind(this),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async loadStocks(options) {
|
|
79
|
+
const { symbol } = options !== null && options !== void 0 ? options : {};
|
|
80
|
+
const isinScraper = this._scraper.getIsinScraper();
|
|
81
|
+
const stocks = (symbol)
|
|
82
|
+
? await isinScraper.fetchListed({ symbol })
|
|
83
|
+
: await Promise.all([
|
|
84
|
+
isinScraper.fetchListedStocks({ exchange: enums_1.Exchange.TWSE }),
|
|
85
|
+
isinScraper.fetchListedStocks({ exchange: enums_1.Exchange.TPEx }),
|
|
86
|
+
]).then(results => results.flat());
|
|
87
|
+
stocks.forEach((_a) => {
|
|
88
|
+
var { symbol } = _a, ticker = __rest(_a, ["symbol"]);
|
|
89
|
+
return this._stocks.set(symbol, Object.assign({ symbol }, ticker));
|
|
90
|
+
});
|
|
91
|
+
return stocks;
|
|
92
|
+
}
|
|
93
|
+
async loadIndices() {
|
|
94
|
+
const misScraper = this._scraper.getMisTwseScraper();
|
|
95
|
+
const data = await Promise.all([
|
|
96
|
+
misScraper.fetchListedIndices({ exchange: enums_1.Exchange.TWSE }),
|
|
97
|
+
misScraper.fetchListedIndices({ exchange: enums_1.Exchange.TPEx }),
|
|
98
|
+
]).then(results => results.flat());
|
|
99
|
+
const indices = data
|
|
100
|
+
.filter((_a) => {
|
|
101
|
+
var { symbol } = _a, ticker = __rest(_a, ["symbol"]);
|
|
102
|
+
const isExist = this._indices.has(symbol);
|
|
103
|
+
if (!isExist)
|
|
104
|
+
this._indices.set(symbol, Object.assign({ symbol }, ticker));
|
|
105
|
+
return !isExist;
|
|
106
|
+
})
|
|
107
|
+
.map(ticker => (0, lodash_1.omit)(ticker, 'ex_ch'));
|
|
108
|
+
return indices;
|
|
109
|
+
}
|
|
110
|
+
async loadFutOpt(options) {
|
|
111
|
+
const { type } = options !== null && options !== void 0 ? options : {};
|
|
112
|
+
const misTaifexScraper = this._scraper.getMisTaifexScraper();
|
|
113
|
+
const futopt = await (() => {
|
|
114
|
+
switch (type) {
|
|
115
|
+
case 'F': return misTaifexScraper.fetchListedFutOpt({ type: 'F' });
|
|
116
|
+
case 'O': return misTaifexScraper.fetchListedFutOpt({ type: 'O' });
|
|
117
|
+
default: return misTaifexScraper.fetchListedFutOpt();
|
|
118
|
+
}
|
|
119
|
+
})();
|
|
120
|
+
futopt.forEach((_a) => {
|
|
121
|
+
var { symbol } = _a, ticker = __rest(_a, ["symbol"]);
|
|
122
|
+
return this._futopt.set(symbol, Object.assign({ symbol }, ticker));
|
|
123
|
+
});
|
|
124
|
+
return futopt;
|
|
125
|
+
}
|
|
126
|
+
async loadFutOptContracts(options) {
|
|
127
|
+
const { symbol, type } = options;
|
|
128
|
+
const isinScraper = this._scraper.getIsinScraper();
|
|
129
|
+
const futopt = (symbol)
|
|
130
|
+
? await isinScraper.fetchListed({ symbol })
|
|
131
|
+
: await isinScraper.fetchListedFutOpt({ type });
|
|
132
|
+
futopt.forEach((_a) => {
|
|
133
|
+
var { symbol } = _a, ticker = __rest(_a, ["symbol"]);
|
|
134
|
+
return this._futopt.set(symbol, Object.assign({ symbol }, ticker));
|
|
135
|
+
});
|
|
136
|
+
return futopt;
|
|
137
|
+
}
|
|
138
|
+
async fetchStocksList(options) {
|
|
139
|
+
const { exchange } = options !== null && options !== void 0 ? options : {};
|
|
140
|
+
const data = await this.loadStocks();
|
|
141
|
+
return exchange ? data.filter(ticker => ticker.exchange === exchange) : data;
|
|
142
|
+
}
|
|
143
|
+
async fetchStocksQuote(options) {
|
|
144
|
+
const { symbol, odd } = options;
|
|
145
|
+
if (!this._stocks.has(symbol)) {
|
|
146
|
+
const stocks = await this.loadStocks({ symbol });
|
|
147
|
+
if (!stocks.length)
|
|
148
|
+
throw new Error('symbol not found');
|
|
149
|
+
}
|
|
150
|
+
const ticker = this._stocks.get(symbol);
|
|
151
|
+
return this._scraper.getMisTwseScraper().fetchStocksQuote({ ticker, odd });
|
|
152
|
+
}
|
|
153
|
+
async fetchStocksHistorical(options) {
|
|
154
|
+
const { date, symbol } = options;
|
|
155
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
156
|
+
const stocks = await this.loadStocks({ symbol });
|
|
157
|
+
if (!stocks.length)
|
|
158
|
+
throw new Error('symbol not found');
|
|
159
|
+
}
|
|
160
|
+
const ticker = this._stocks.get(symbol);
|
|
161
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
162
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
163
|
+
? await this._scraper.getTpexScraper().fetchStocksHistorical({ date, symbol })
|
|
164
|
+
: await this._scraper.getTwseScraper().fetchStocksHistorical({ date, symbol });
|
|
165
|
+
}
|
|
166
|
+
async fetchStocksInstitutional(options) {
|
|
167
|
+
const { date, symbol } = options;
|
|
168
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
169
|
+
const stocks = await this.loadStocks({ symbol });
|
|
170
|
+
if (!stocks.length)
|
|
171
|
+
throw new Error('symbol not found');
|
|
172
|
+
}
|
|
173
|
+
const ticker = this._stocks.get(symbol);
|
|
174
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
175
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
176
|
+
? await this._scraper.getTpexScraper().fetchStocksInstitutional({ date, symbol })
|
|
177
|
+
: await this._scraper.getTwseScraper().fetchStocksInstitutional({ date, symbol });
|
|
178
|
+
}
|
|
179
|
+
async fetchStocksValues(options) {
|
|
180
|
+
const { date, symbol } = options;
|
|
181
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
182
|
+
const stocks = await this.loadStocks({ symbol });
|
|
183
|
+
if (!stocks.length)
|
|
184
|
+
throw new Error('symbol not found');
|
|
185
|
+
}
|
|
186
|
+
const ticker = this._stocks.get(symbol);
|
|
187
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
188
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
189
|
+
? await this._scraper.getTpexScraper().fetchStocksValues({ date, symbol })
|
|
190
|
+
: await this._scraper.getTwseScraper().fetchStocksValues({ date, symbol });
|
|
191
|
+
}
|
|
192
|
+
async fetchStocksSplits(options) {
|
|
193
|
+
const { startDate, endDate, symbol } = options;
|
|
194
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
195
|
+
const stocks = await this.loadStocks({ symbol });
|
|
196
|
+
if (!stocks.length)
|
|
197
|
+
throw new Error('symbol not found');
|
|
198
|
+
}
|
|
199
|
+
const ticker = this._stocks.get(symbol);
|
|
200
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
201
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
202
|
+
? await this._scraper.getTpexScraper().fetchStocksSplits({ symbol, startDate, endDate })
|
|
203
|
+
: await this._scraper.getTwseScraper().fetchStocksSplits({ symbol, startDate, endDate });
|
|
204
|
+
}
|
|
205
|
+
async fetchStocksEtfSplits(options) {
|
|
206
|
+
const { startDate, endDate, symbol, reverseSplit } = options;
|
|
207
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
208
|
+
const stocks = await this.loadStocks({ symbol });
|
|
209
|
+
if (!stocks.length)
|
|
210
|
+
throw new Error('symbol not found');
|
|
211
|
+
}
|
|
212
|
+
const ticker = this._stocks.get(symbol);
|
|
213
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
214
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
215
|
+
? await (reverseSplit
|
|
216
|
+
? this._scraper.getTpexScraper().fetchStocksEtfReverseSplits({ symbol, startDate, endDate })
|
|
217
|
+
: this._scraper.getTpexScraper().fetchStocksEtfSplits({ symbol, startDate, endDate }))
|
|
218
|
+
: await this._scraper.getTwseScraper().fetchStocksEtfSplits({ symbol, startDate, endDate, reverseSplit });
|
|
219
|
+
}
|
|
220
|
+
async fetchStocksDividendsAnnouncement(options) {
|
|
221
|
+
const { exchange = enums_1.Exchange.TWSE, symbol, includeDetail } = options || {};
|
|
222
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
223
|
+
? await this._scraper.getTpexScraper().fetchStocksDividendsAnnouncement({ symbol })
|
|
224
|
+
: await this._scraper.getTwseScraper().fetchStocksDividendsAnnouncement({ symbol, includeDetail });
|
|
225
|
+
}
|
|
226
|
+
async fetchStocksCapitalReductionAnnouncement(options) {
|
|
227
|
+
const { exchange = enums_1.Exchange.TWSE, symbol, includeDetail } = options || {};
|
|
228
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
229
|
+
? await this._scraper.getTpexScraper().fetchStocksCapitalReductionAnnouncement({ symbol })
|
|
230
|
+
: await this._scraper.getTwseScraper().fetchStocksCapitalReductionAnnouncement({ symbol, includeDetail });
|
|
231
|
+
}
|
|
232
|
+
async fetchStocksSplitAnnouncement(options) {
|
|
233
|
+
const { exchange = enums_1.Exchange.TWSE, symbol, includeDetail } = options || {};
|
|
234
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
235
|
+
? await this._scraper.getTpexScraper().fetchStocksSplitAnnouncement({ symbol })
|
|
236
|
+
: await this._scraper.getTwseScraper().fetchStocksSplitAnnouncement({ symbol, includeDetail });
|
|
237
|
+
}
|
|
238
|
+
async fetchStocksEtfSplitAnnouncement(options) {
|
|
239
|
+
const { exchange = enums_1.Exchange.TWSE, symbol, splitType } = options || {};
|
|
240
|
+
if (exchange === enums_1.Exchange.TPEx) {
|
|
241
|
+
// TPEx has separate endpoints for split and reverse split
|
|
242
|
+
const data = splitType === '反分割'
|
|
243
|
+
? await this._scraper.getTpexScraper().fetchStocksEtfReverseSplitAnnouncement({ symbol })
|
|
244
|
+
: splitType === '分割'
|
|
245
|
+
? await this._scraper.getTpexScraper().fetchStocksEtfSplitAnnouncement({ symbol })
|
|
246
|
+
: [
|
|
247
|
+
...await this._scraper.getTpexScraper().fetchStocksEtfSplitAnnouncement({ symbol }),
|
|
248
|
+
...await this._scraper.getTpexScraper().fetchStocksEtfReverseSplitAnnouncement({ symbol })
|
|
249
|
+
];
|
|
250
|
+
return data;
|
|
251
|
+
}
|
|
252
|
+
// TWSE returns all split types in one call, filter by splitType if specified
|
|
253
|
+
const data = await this._scraper.getTwseScraper().fetchStocksEtfSplitAnnouncement({ symbol });
|
|
254
|
+
return splitType ? data.filter(item => item.splitType === splitType) : data;
|
|
255
|
+
}
|
|
256
|
+
async fetchStocksCapitalReductions(options) {
|
|
257
|
+
const { symbol, startDate, endDate, includeDetail } = options;
|
|
258
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
259
|
+
const stocks = await this.loadStocks({ symbol });
|
|
260
|
+
if (!stocks.length)
|
|
261
|
+
throw new Error('symbol not found');
|
|
262
|
+
}
|
|
263
|
+
const ticker = this._stocks.get(symbol);
|
|
264
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
265
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
266
|
+
? await this._scraper.getTpexScraper().fetchStocksCapitalReductions({ symbol, startDate, endDate, includeDetail })
|
|
267
|
+
: await this._scraper.getTwseScraper().fetchStocksCapitalReductions({ symbol, startDate, endDate, includeDetail });
|
|
268
|
+
}
|
|
269
|
+
async fetchStocksListingApplicants(options) {
|
|
270
|
+
const { exchange = enums_1.Exchange.TWSE, symbol, year } = options || {};
|
|
271
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
272
|
+
? await this._scraper.getTpexScraper().fetchStocksListingApplicants({ symbol, year })
|
|
273
|
+
: await this._scraper.getTwseScraper().fetchStocksListingApplicants({
|
|
274
|
+
symbol,
|
|
275
|
+
year: year === 'ALL' ? undefined : year
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
async fetchStocksDividends(options) {
|
|
279
|
+
const { symbol, startDate, endDate, includeDetail } = options;
|
|
280
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
281
|
+
const stocks = await this.loadStocks({ symbol });
|
|
282
|
+
if (!stocks.length)
|
|
283
|
+
throw new Error('symbol not found');
|
|
284
|
+
}
|
|
285
|
+
const ticker = this._stocks.get(symbol);
|
|
286
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
287
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
288
|
+
? await this._scraper.getTpexScraper().fetchStocksDividends({ symbol, startDate, endDate, includeDetail })
|
|
289
|
+
: await this._scraper.getTwseScraper().fetchStocksDividends({ symbol, startDate, endDate, includeDetail });
|
|
290
|
+
}
|
|
291
|
+
async fetchStocksFiniHoldings(options) {
|
|
292
|
+
const { date, symbol } = options;
|
|
293
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
294
|
+
const stocks = await this.loadStocks({ symbol });
|
|
295
|
+
if (!stocks.length)
|
|
296
|
+
throw new Error('symbol not found');
|
|
297
|
+
}
|
|
298
|
+
const ticker = this._stocks.get(symbol);
|
|
299
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
300
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
301
|
+
? await this._scraper.getTpexScraper().fetchStocksFiniHoldings({ date, symbol })
|
|
302
|
+
: await this._scraper.getTwseScraper().fetchStocksFiniHoldings({ date, symbol });
|
|
303
|
+
}
|
|
304
|
+
async fetchStocksMarginTrades(options) {
|
|
305
|
+
const { date, symbol } = options;
|
|
306
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
307
|
+
const stocks = await this.loadStocks({ symbol });
|
|
308
|
+
if (!stocks.length)
|
|
309
|
+
throw new Error('symbol not found');
|
|
310
|
+
}
|
|
311
|
+
const ticker = this._stocks.get(symbol);
|
|
312
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
313
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
314
|
+
? await this._scraper.getTpexScraper().fetchStocksMarginTrades({ date, symbol })
|
|
315
|
+
: await this._scraper.getTwseScraper().fetchStocksMarginTrades({ date, symbol });
|
|
316
|
+
}
|
|
317
|
+
async fetchStocksShortSales(options) {
|
|
318
|
+
const { date, symbol } = options;
|
|
319
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
320
|
+
const stocks = await this.loadStocks({ symbol });
|
|
321
|
+
if (!stocks.length)
|
|
322
|
+
throw new Error('symbol not found');
|
|
323
|
+
}
|
|
324
|
+
const ticker = this._stocks.get(symbol);
|
|
325
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
326
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
327
|
+
? await this._scraper.getTpexScraper().fetchStocksShortSales({ date, symbol })
|
|
328
|
+
: await this._scraper.getTwseScraper().fetchStocksShortSales({ date, symbol });
|
|
329
|
+
}
|
|
330
|
+
async fetchStocksShareholders(options) {
|
|
331
|
+
if (!options)
|
|
332
|
+
return this._scraper.getTdccScraper().fetchStocksShareholdersRecentWeek();
|
|
333
|
+
const { date, symbol } = options;
|
|
334
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
335
|
+
const stocks = await this.loadStocks({ symbol });
|
|
336
|
+
if (!stocks.length)
|
|
337
|
+
throw new Error('symbol not found');
|
|
338
|
+
}
|
|
339
|
+
return (!date)
|
|
340
|
+
? this._scraper.getTdccScraper().fetchStocksShareholdersRecentWeek({ symbol })
|
|
341
|
+
: this._scraper.getTdccScraper().fetchStocksShareholders({ date, symbol });
|
|
342
|
+
}
|
|
343
|
+
async fetchStocksEps(options) {
|
|
344
|
+
const { symbol, year, quarter } = options;
|
|
345
|
+
if (!options.exchange && !options.symbol) {
|
|
346
|
+
throw new Error('Either "exchange" or "symbol" options must be specified');
|
|
347
|
+
}
|
|
348
|
+
if (options.exchange && options.symbol) {
|
|
349
|
+
throw new Error('One and only one of the "exchange" or "symbol" options must be specified');
|
|
350
|
+
}
|
|
351
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
352
|
+
const stocks = await this.loadStocks({ symbol });
|
|
353
|
+
if (!stocks.length)
|
|
354
|
+
throw new Error('symbol not found');
|
|
355
|
+
}
|
|
356
|
+
const ticker = this._stocks.get(symbol);
|
|
357
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
358
|
+
return this._scraper.getMopsScraper().fetchStocksEps({ exchange, year, quarter, symbol });
|
|
359
|
+
}
|
|
360
|
+
async fetchStocksRevenue(options) {
|
|
361
|
+
const { symbol, year, month, foreign } = options;
|
|
362
|
+
if (!options.exchange && !options.symbol) {
|
|
363
|
+
throw new Error('Either "exchange" or "symbol" options must be specified');
|
|
364
|
+
}
|
|
365
|
+
if (options.exchange && options.symbol) {
|
|
366
|
+
throw new Error('One and only one of the "exchange" or "symbol" options must be specified');
|
|
367
|
+
}
|
|
368
|
+
if (symbol && !this._stocks.has(symbol)) {
|
|
369
|
+
const stocks = await this.loadStocks({ symbol });
|
|
370
|
+
if (!stocks.length)
|
|
371
|
+
throw new Error('symbol not found');
|
|
372
|
+
}
|
|
373
|
+
const ticker = this._stocks.get(symbol);
|
|
374
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
375
|
+
return this._scraper.getMopsScraper().fetchStocksRevenue({ exchange, year, month, foreign, symbol });
|
|
376
|
+
}
|
|
377
|
+
async getIndicesList(options) {
|
|
378
|
+
const { exchange } = options !== null && options !== void 0 ? options : {};
|
|
379
|
+
const data = await this.loadIndices();
|
|
380
|
+
return exchange ? data.filter(ticker => ticker.exchange === exchange) : data;
|
|
381
|
+
}
|
|
382
|
+
async getIndicesQuote(options) {
|
|
383
|
+
const { symbol } = options;
|
|
384
|
+
if (!this._indices.has(symbol)) {
|
|
385
|
+
const indices = await this.loadIndices();
|
|
386
|
+
if (!(0, lodash_1.map)(indices, 'symbol').includes(symbol))
|
|
387
|
+
throw new Error('symbol not found');
|
|
388
|
+
}
|
|
389
|
+
const ticker = this._indices.get(symbol);
|
|
390
|
+
return this._scraper.getMisTwseScraper().fetchIndicesQuote({ ticker });
|
|
391
|
+
}
|
|
392
|
+
async getIndicesHistorical(options) {
|
|
393
|
+
const { date, symbol } = options;
|
|
394
|
+
if (symbol && !this._indices.has(symbol)) {
|
|
395
|
+
const indices = await this.loadIndices();
|
|
396
|
+
if (!(0, lodash_1.map)(indices, 'symbol').includes(symbol))
|
|
397
|
+
throw new Error('symbol not found');
|
|
398
|
+
}
|
|
399
|
+
const ticker = this._indices.get(symbol);
|
|
400
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
401
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
402
|
+
? await this._scraper.getTpexScraper().fetchIndicesHistorical({ date, symbol })
|
|
403
|
+
: await this._scraper.getTwseScraper().fetchIndicesHistorical({ date, symbol });
|
|
404
|
+
}
|
|
405
|
+
async getIndicesTrades(options) {
|
|
406
|
+
const { date, symbol } = options;
|
|
407
|
+
if (symbol && !this._indices.has(symbol)) {
|
|
408
|
+
const indices = await this.loadIndices();
|
|
409
|
+
if (!(0, lodash_1.map)(indices, 'symbol').includes(symbol))
|
|
410
|
+
throw new Error('symbol not found');
|
|
411
|
+
}
|
|
412
|
+
const ticker = this._indices.get(symbol);
|
|
413
|
+
const exchange = symbol ? ticker.exchange : options.exchange;
|
|
414
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
415
|
+
? await this._scraper.getTpexScraper().fetchIndicesTrades({ date, symbol })
|
|
416
|
+
: await this._scraper.getTwseScraper().fetchIndicesTrades({ date, symbol });
|
|
417
|
+
}
|
|
418
|
+
async getMarketTrades(options) {
|
|
419
|
+
const { date, exchange } = options;
|
|
420
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
421
|
+
? await this._scraper.getTpexScraper().fetchMarketTrades({ date })
|
|
422
|
+
: await this._scraper.getTwseScraper().fetchMarketTrades({ date });
|
|
423
|
+
}
|
|
424
|
+
async getMarketBreadth(options) {
|
|
425
|
+
const { date, exchange } = options;
|
|
426
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
427
|
+
? await this._scraper.getTpexScraper().fetchMarketBreadth({ date })
|
|
428
|
+
: await this._scraper.getTwseScraper().fetchMarketBreadth({ date });
|
|
429
|
+
}
|
|
430
|
+
async getMarketInstitutional(options) {
|
|
431
|
+
const { date, exchange } = options;
|
|
432
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
433
|
+
? await this._scraper.getTpexScraper().fetchMarketInstitutional({ date })
|
|
434
|
+
: await this._scraper.getTwseScraper().fetchMarketInstitutional({ date });
|
|
435
|
+
}
|
|
436
|
+
async getMarketMarginTrades(options) {
|
|
437
|
+
const { date, exchange } = options;
|
|
438
|
+
return (exchange === enums_1.Exchange.TPEx)
|
|
439
|
+
? await this._scraper.getTpexScraper().fetchMarketMarginTrades({ date })
|
|
440
|
+
: await this._scraper.getTwseScraper().fetchMarketMarginTrades({ date });
|
|
441
|
+
}
|
|
442
|
+
async getFutOptList(options) {
|
|
443
|
+
const { type, availableContracts } = options !== null && options !== void 0 ? options : {};
|
|
444
|
+
return availableContracts
|
|
445
|
+
? await this.loadFutOptContracts({ type })
|
|
446
|
+
: await this.loadFutOpt({ type });
|
|
447
|
+
}
|
|
448
|
+
async getFutOptQuote(options) {
|
|
449
|
+
const { symbol, afterhours } = options;
|
|
450
|
+
if (!this._futopt.has(symbol)) {
|
|
451
|
+
const futopt = (symbol.length === 3)
|
|
452
|
+
? await this.loadFutOpt()
|
|
453
|
+
: await this.loadFutOptContracts({ symbol });
|
|
454
|
+
// @ts-ignore
|
|
455
|
+
if (!(0, lodash_1.map)(futopt, 'symbol').includes(symbol))
|
|
456
|
+
throw new Error('symbol not found');
|
|
457
|
+
}
|
|
458
|
+
const ticker = this._futopt.get(symbol);
|
|
459
|
+
return (ticker.symbol.length === 3)
|
|
460
|
+
? this._scraper.getMisTaifexScraper().fetchFutOptQuoteList({ ticker, afterhours })
|
|
461
|
+
: this._scraper.getMisTaifexScraper().fetchFutOptQuoteDetail({ ticker, afterhours });
|
|
462
|
+
}
|
|
463
|
+
async getFutOptHistorical(options) {
|
|
464
|
+
const { date, symbol, afterhours } = options;
|
|
465
|
+
if (symbol && !this._futopt.has(symbol)) {
|
|
466
|
+
const futopt = await this.loadFutOpt();
|
|
467
|
+
if (!(0, lodash_1.map)(futopt, 'symbol').includes(symbol))
|
|
468
|
+
throw new Error('symbol not found');
|
|
469
|
+
}
|
|
470
|
+
const ticker = this._futopt.get(symbol);
|
|
471
|
+
const type = symbol ? ticker.type : options.type;
|
|
472
|
+
return (type === 'O')
|
|
473
|
+
? this._scraper.getTaifexScraper().fetchOptionsHistorical({ date, symbol, afterhours })
|
|
474
|
+
: this._scraper.getTaifexScraper().fetchFuturesHistorical({ date, symbol, afterhours });
|
|
475
|
+
}
|
|
476
|
+
async getFutOptInstitutional(options) {
|
|
477
|
+
const { date, symbol } = options;
|
|
478
|
+
const type = (symbol.charAt(2) === 'O') ? 'O' : 'F';
|
|
479
|
+
return (type === 'O')
|
|
480
|
+
? this._scraper.getTaifexScraper().fetchOptionsInstitutional({ date, symbol })
|
|
481
|
+
: this._scraper.getTaifexScraper().fetchFuturesInstitutional({ date, symbol });
|
|
482
|
+
}
|
|
483
|
+
async getFutOptLargeTraders(options) {
|
|
484
|
+
const { date, symbol } = options;
|
|
485
|
+
const type = (symbol.charAt(2) === 'O') ? 'O' : 'F';
|
|
486
|
+
return (type === 'O')
|
|
487
|
+
? this._scraper.getTaifexScraper().fetchOptionsLargeTraders({ date, symbol })
|
|
488
|
+
: this._scraper.getTaifexScraper().fetchFuturesLargeTraders({ date, symbol });
|
|
489
|
+
}
|
|
490
|
+
async getFutOptMxfRetailPosition(options) {
|
|
491
|
+
const { date } = options;
|
|
492
|
+
return this._scraper.getTaifexScraper().fetchMxfRetailPosition({ date });
|
|
493
|
+
}
|
|
494
|
+
async getFutOptTmfRetailPosition(options) {
|
|
495
|
+
const { date } = options;
|
|
496
|
+
return this._scraper.getTaifexScraper().fetchTmfRetailPosition({ date });
|
|
497
|
+
}
|
|
498
|
+
async getFutOptTxoPutCallRatio(options) {
|
|
499
|
+
const { date } = options;
|
|
500
|
+
return this._scraper.getTaifexScraper().fetchTxoPutCallRatio({ date });
|
|
501
|
+
}
|
|
502
|
+
async getFutOptExchangeRates(options) {
|
|
503
|
+
const { date } = options;
|
|
504
|
+
return this._scraper.getTaifexScraper().fetchExchangeRates({ date });
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
exports.TwStock = TwStock;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asExchange = void 0;
|
|
4
|
+
const enums_1 = require("../enums");
|
|
5
|
+
function asExchange(market) {
|
|
6
|
+
const exchanges = {
|
|
7
|
+
[enums_1.Market.TSE]: enums_1.Exchange.TWSE,
|
|
8
|
+
[enums_1.Market.OTC]: enums_1.Exchange.TPEx,
|
|
9
|
+
'上市': enums_1.Exchange.TWSE,
|
|
10
|
+
'上櫃': enums_1.Exchange.TPEx,
|
|
11
|
+
'期貨及選擇權': enums_1.Exchange.TAIFEX,
|
|
12
|
+
};
|
|
13
|
+
return exchanges[market];
|
|
14
|
+
}
|
|
15
|
+
exports.asExchange = asExchange;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function asIndex(index: string): string;
|