tw-stock-mcp 0.1.2 → 0.1.3
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/README.md +4 -4
- package/build/core/institutional.js +11 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,19 +15,19 @@ Requires Node.js 22 or later. Pin a version so an upstream change can never reac
|
|
|
15
15
|
**Claude Code**
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
claude mcp add tw-stock -- npx -y npm:tw-stock-mcp@0.1.
|
|
18
|
+
claude mcp add tw-stock -- npx -y npm:tw-stock-mcp@0.1.3
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
**Codex CLI**
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
|
-
codex mcp add tw-stock -- npx -y npm:tw-stock-mcp@0.1.
|
|
24
|
+
codex mcp add tw-stock -- npx -y npm:tw-stock-mcp@0.1.3
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
**VS Code**
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
code --add-mcp '{"name":"tw-stock","command":"npx","args":["-y","npm:tw-stock-mcp@0.1.
|
|
30
|
+
code --add-mcp '{"name":"tw-stock","command":"npx","args":["-y","npm:tw-stock-mcp@0.1.3"]}'
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
**Claude Desktop, Cursor and other clients** — add to the client's MCP config (`claude_desktop_config.json`, `~/.cursor/mcp.json`, …):
|
|
@@ -37,7 +37,7 @@ code --add-mcp '{"name":"tw-stock","command":"npx","args":["-y","npm:tw-stock-mc
|
|
|
37
37
|
"mcpServers": {
|
|
38
38
|
"tw-stock": {
|
|
39
39
|
"command": "npx",
|
|
40
|
-
"args": ["-y", "npm:tw-stock-mcp@0.1.
|
|
40
|
+
"args": ["-y", "npm:tw-stock-mcp@0.1.3"]
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -21,16 +21,17 @@ export function institutionalUrl(date, market) {
|
|
|
21
21
|
return `https://www.twse.com.tw/rwd/zh/fund/T86?${query}`;
|
|
22
22
|
}
|
|
23
23
|
export function summaryUrl(date) {
|
|
24
|
-
|
|
24
|
+
// BFI82U ignores `date`: it needs type=day and dayDate, or it silently answers with the latest day.
|
|
25
|
+
const query = new URLSearchParams({ type: 'day', dayDate: date.replaceAll('-', ''), response: 'json' });
|
|
25
26
|
return `https://www.twse.com.tw/rwd/zh/fund/BFI82U?${query}`;
|
|
26
27
|
}
|
|
27
|
-
/** Data rows, or null when the exchange has nothing for that date. */
|
|
28
|
+
/** Data rows, or null when the exchange has nothing for that date (no trading, or not published yet). */
|
|
28
29
|
function rowsOf(data) {
|
|
29
30
|
if (!data || typeof data !== 'object')
|
|
30
31
|
throw new Error('Invalid institutional response');
|
|
31
32
|
const response = data;
|
|
32
33
|
if (typeof response.stat === 'string' && response.stat.toLowerCase() !== 'ok') {
|
|
33
|
-
if (response.stat.includes('沒有符合條件'))
|
|
34
|
+
if (response.stat.includes('沒有符合條件') || response.stat.includes('大於可查詢最大日期'))
|
|
34
35
|
return null;
|
|
35
36
|
throw new Error(`Institutional data unavailable: ${response.stat}`);
|
|
36
37
|
}
|
|
@@ -74,10 +75,15 @@ const SUMMARY_LABELS = {
|
|
|
74
75
|
外資自營商: 'foreign_dealer',
|
|
75
76
|
合計: 'total',
|
|
76
77
|
};
|
|
77
|
-
|
|
78
|
+
/** `date` (YYYY-MM-DD) is the day asked for: an answer for any other day is refused rather than mislabelled. */
|
|
79
|
+
export function parseSummary(data, date) {
|
|
78
80
|
const rows = rowsOf(data);
|
|
79
81
|
if (!rows)
|
|
80
82
|
return null;
|
|
83
|
+
const answered = data.date;
|
|
84
|
+
if (date && typeof answered === 'string' && answered !== date.replaceAll('-', '')) {
|
|
85
|
+
throw new Error(`TWSE answered with the summary for ${answered} instead of ${date}`);
|
|
86
|
+
}
|
|
81
87
|
const summary = { market: 'tse', unit: 'TWD' };
|
|
82
88
|
for (const row of rows) {
|
|
83
89
|
const key = SUMMARY_LABELS[String(row[0]).trim()];
|
|
@@ -99,5 +105,5 @@ export function loadInstitutional(date, market, signal) {
|
|
|
99
105
|
}
|
|
100
106
|
export function loadSummary(date, signal) {
|
|
101
107
|
const url = summaryUrl(date);
|
|
102
|
-
return cache.get(url, date, async () => parseSummary(await requestJson(url, { signal })));
|
|
108
|
+
return cache.get(url, date, async () => parseSummary(await requestJson(url, { signal }), date));
|
|
103
109
|
}
|