bitbank-lab-mcp 0.4.0 → 0.5.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.
Files changed (44) hide show
  1. package/lib/datetime.ts +41 -0
  2. package/lib/http.ts +40 -2
  3. package/lib/pattern-diagrams.ts +118 -45
  4. package/package.json +6 -6
  5. package/src/handlers/analyzeMyPortfolioHandler.ts +441 -30
  6. package/src/handlers/detectPatternsHandler.ts +65 -10
  7. package/src/handlers/detectPatternsViewsHandler.ts +966 -79
  8. package/src/handlers/portfolio/calc.ts +389 -57
  9. package/src/handlers/portfolio/types.ts +134 -4
  10. package/src/mcp-apps-hydration.ts +191 -0
  11. package/src/private/elicitation.ts +48 -7
  12. package/src/private/schemas.ts +211 -17
  13. package/src/prompts/intermediate.ts +28 -0
  14. package/src/schema/patterns.ts +850 -28
  15. package/src/server.ts +9 -1
  16. package/tools/detect_patterns.ts +268 -36
  17. package/tools/get_candles.ts +133 -47
  18. package/tools/patterns/bar-thresholds.ts +130 -0
  19. package/tools/patterns/candidate-filter.ts +106 -0
  20. package/tools/patterns/config.ts +475 -30
  21. package/tools/patterns/detect_doubles.ts +933 -354
  22. package/tools/patterns/detect_hs.ts +1636 -235
  23. package/tools/patterns/detect_pennants.ts +45 -16
  24. package/tools/patterns/detect_triangles.ts +158 -20
  25. package/tools/patterns/detect_triples.ts +1252 -178
  26. package/tools/patterns/detect_wedges.ts +178 -45
  27. package/tools/patterns/helpers.ts +132 -125
  28. package/tools/patterns/min-bars.ts +127 -0
  29. package/tools/patterns/mutual-exclusion.ts +199 -0
  30. package/tools/patterns/period.ts +7 -10
  31. package/tools/patterns/ranking.ts +11 -2
  32. package/tools/patterns/reversal-gate.ts +205 -0
  33. package/tools/patterns/scan-window.ts +169 -0
  34. package/tools/patterns/scoring.ts +73 -0
  35. package/tools/patterns/structural.ts +1227 -3
  36. package/tools/patterns/swing.ts +44 -4
  37. package/tools/patterns/target-confounders.ts +171 -0
  38. package/tools/patterns/target-reach.ts +551 -0
  39. package/tools/patterns/types.ts +146 -1
  40. package/tools/private/analyze_my_portfolio.ts +1 -1
  41. package/tools/private/preview_cancel_order.ts +46 -7
  42. package/tsconfig.json +2 -2
  43. package/ui/cancel-confirm/dist/cancel-confirm.html +30 -30
  44. package/ui/order-confirm/dist/order-confirm.html +44 -44
package/lib/datetime.ts CHANGED
@@ -182,6 +182,47 @@ export function parseIso8601(value: string): dayjs.Dayjs | null {
182
182
  return null;
183
183
  }
184
184
 
185
+ /**
186
+ * 日足未満(intraday)の時間足。
187
+ * 暦日だけで表示すると足の位置が特定できず「直近◯時間がスキャンされていない」という
188
+ * 誤読を招く(issue #200 の誤読の直接原因)ため、これらは時刻まで表示する。
189
+ *
190
+ * issue #233: 元は `tools/patterns/period.ts` にあったが、`lib/pattern-diagrams.ts`
191
+ * (構造図)からも必要になったため `lib/` へ移した。`lib/` → `tools/` の逆方向依存を
192
+ * 作らないための移動で、時間足の分類という土台的な判定は `lib/` 側が定位置。
193
+ * `tools/patterns/period.ts` は互換のため re-export している。
194
+ */
195
+ const INTRADAY_TYPES = new Set(['1min', '5min', '15min', '30min', '1hour', '4hour', '8hour', '12hour']);
196
+
197
+ /** 時間足が日足未満(= 表示に時刻まで含めるべき)か。 */
198
+ export function isIntradayType(type: string): boolean {
199
+ return INTRADAY_TYPES.has(type);
200
+ }
201
+
202
+ /**
203
+ * UTC ISO 文字列を、時間足に応じて暦日 `YYYY-MM-DD`(日足以上)または分単位
204
+ * `YYYY-MM-DD HH:mm`(intraday)へ整形する(issue #200 要件 F-1 の共通実装)。
205
+ *
206
+ * **暦日に潰すと intraday では 24 本が同じラベルになり、どの足かを特定できない。**
207
+ * `detect_patterns` の `content` はブレイク足・構成点・ターゲット初到達といった
208
+ * 「どの足か」が意味を持つ行を出すので、時間足を見て粒度を切り替える必要がある。
209
+ *
210
+ * `src/handlers/detectPatternsViewsHandler.ts` の `toDateOrTime` と
211
+ * `tools/detect_patterns.ts` の `res.summary` が**別々に同じ判定を持っていて片方だけ
212
+ * 暦日に潰れていた**(#288 Phase 2 のレビュー指摘)ので、判定をここに 1 本化した。
213
+ *
214
+ * 値が空 / parse 失敗 / 不正 tz のときは `null` を返す。**フォールバックは呼び出し側が決める**
215
+ * (`'n/a'` を出す側と、元の ISO をそのまま出す側がある)。
216
+ */
217
+ export function formatDateOrTimeInTz(iso: string | number | undefined | null, tz: string, type: string): string | null {
218
+ if (iso == null || iso === '') return null;
219
+ const ms = typeof iso === 'number' ? iso : Date.parse(iso);
220
+ if (!Number.isFinite(ms)) return null;
221
+ if (!isIntradayType(type)) return formatDateInTz(ms, tz);
222
+ const withTz = toIsoWithTz(ms, resolveTz(tz)); // 'YYYY-MM-DDTHH:mm:ss'
223
+ return withTz ? `${withTz.slice(0, 10)} ${withTz.slice(11, 16)}` : null;
224
+ }
225
+
185
226
  /**
186
227
  * ISO日付文字列を "M/D(曜日)" 形式に変換
187
228
  * 例: "2026-04-09T00:00:00Z" → "4/9(木)"
package/lib/http.ts CHANGED
@@ -43,6 +43,38 @@ export interface FetchJsonOptions {
43
43
  /** リトライ待機の上限(30秒) */
44
44
  const MAX_RETRY_WAIT_MS = 30_000;
45
45
 
46
+ /**
47
+ * HTTP ステータス由来の失敗。**リトライしてよいかを呼び出し側が判定できる**ようにするため、
48
+ * ステータスコードを保持する(`message` は従来どおり `HTTP <status> <statusText>`。
49
+ * `get_candles` 等が本文の `404` を正規表現で拾っているので文言は変えない)。
50
+ */
51
+ export class HttpStatusError extends Error {
52
+ readonly status: number;
53
+
54
+ constructor(status: number, statusText: string) {
55
+ super(`HTTP ${status} ${statusText}`);
56
+ this.name = 'HttpStatusError';
57
+ this.status = status;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * この HTTP ステータスをもう一度叩く価値があるか。
63
+ *
64
+ * 4xx は上流の「その資源は無い / 要求が不正」の表明で、**同じ URL を叩き直しても永久に同じ結果**
65
+ * になる。bitbank `/candlestick` は上場前・未来の期間キーに 404 を返すため
66
+ * (`docs/internal/bitbank-candle-tz.md`)、ここをリトライすると上場前の 1 chunk につき
67
+ * リクエストが 3 倍になり、レート制限を自分で誘発して**他の chunk の成功率を下げる**(#84)。
68
+ *
69
+ * 例外は 2 つだけ:
70
+ * - 408 Request Timeout: 一時的な遅延なので再試行の価値がある
71
+ * - 429 Too Many Requests: `Retry-After` を解釈する専用経路で扱う(ここには到達しない)
72
+ */
73
+ export function isRetriableHttpStatus(status: number): boolean {
74
+ if (status === 408 || status === 429) return true;
75
+ return status < 400 || status >= 500;
76
+ }
77
+
46
78
  /** 汎用リトライの待機ベース(ms)。試行回数 i に対して BASE * 2^i を待つ */
47
79
  const RETRY_BACKOFF_BASE_MS = 200;
48
80
 
@@ -136,13 +168,16 @@ export async function fetchJson<T = unknown>(
136
168
  }
137
169
  throw new Error('レート制限超過 (HTTP 429)。しばらく待ってから再試行してください');
138
170
  }
139
- if (!res.ok) throw new Error(`HTTP ${res.status} ${res.statusText}`);
171
+ if (!res.ok) throw new HttpStatusError(res.status, res.statusText);
140
172
  const json: unknown = await res.json();
141
173
  if (schema) return schema.parse(json) as T;
142
174
  return json as T;
143
175
  } catch (e) {
144
176
  clearTimeout(t);
145
177
  lastErr = e;
178
+ // 恒久的な HTTP 失敗(404 等)はリトライしない。何度叩いても同じ結果で、
179
+ // 待ち時間とレート制限枠だけを消費する(#84)。
180
+ if (e instanceof HttpStatusError && !isRetriableHttpStatus(e.status)) break;
146
181
  if (i < retries) await new Promise((r) => setTimeout(r, retryBackoffMs(i)));
147
182
  }
148
183
  }
@@ -178,7 +213,7 @@ export async function fetchJsonWithRateLimit<T = unknown>(
178
213
  }
179
214
  throw new Error('レート制限超過 (HTTP 429)。しばらく待ってから再試行してください');
180
215
  }
181
- if (!res.ok) throw new Error(`HTTP ${res.status} ${res.statusText}`);
216
+ if (!res.ok) throw new HttpStatusError(res.status, res.statusText);
182
217
  const rateLimit = extractRateLimit(res.headers);
183
218
  const json: unknown = await res.json();
184
219
  const data = schema ? (schema.parse(json) as T) : (json as T);
@@ -186,6 +221,9 @@ export async function fetchJsonWithRateLimit<T = unknown>(
186
221
  } catch (e) {
187
222
  clearTimeout(t);
188
223
  lastErr = e;
224
+ // 恒久的な HTTP 失敗(404 等)はリトライしない。何度叩いても同じ結果で、
225
+ // 待ち時間とレート制限枠だけを消費する(#84)。
226
+ if (e instanceof HttpStatusError && !isRetriableHttpStatus(e.status)) break;
189
227
  if (i < retries) await new Promise((r) => setTimeout(r, retryBackoffMs(i)));
190
228
  }
191
229
  }
@@ -1,4 +1,4 @@
1
- import { dayjs } from './datetime.js';
1
+ import { dayjs, isIntradayType, resolveTz, toIsoWithTz } from './datetime.js';
2
2
 
3
3
  export interface PatternDiagramData {
4
4
  svg: string;
@@ -47,27 +47,95 @@ function getPatternLabel(patternType: string): string {
47
47
  }
48
48
  }
49
49
 
50
- function formatDateShort(iso?: string): string {
50
+ /**
51
+ * pivot / range の日付を「M/D」に整形する。
52
+ *
53
+ * issue #200 要件 F-2: 旧実装は `.utc()` 固定だったため、JST 09:00 より前のピボット
54
+ * (UTC で見ると前日)が構造図とスイング一覧(`detectPatternsViewsHandler.ts`)で
55
+ * 1 日ずれていた(例: 1hour の 8/28 00:00 JST が構造図では 8/27)。
56
+ *
57
+ * `tz` 未指定時は `resolveTz(undefined)` が `Asia/Tokyo` にフォールバックする
58
+ * (呼び出し側 tz の既定値と同じ)。
59
+ */
60
+ function formatDateShort(iso: string | undefined, tz: string | undefined): string {
51
61
  if (!iso) return '';
52
- const d = dayjs(iso).utc();
62
+ const d = dayjs(iso).tz(resolveTz(tz));
53
63
  return `${d.month() + 1}/${d.date()}`;
54
64
  }
55
65
 
66
+ /**
67
+ * 構造図に出す 1 点の日時表示(issue #233)。
68
+ *
69
+ * intraday(1hour 等)では `M/D` だけだと 24 本が同じラベルに潰れ、5 つのピボットが
70
+ * すべて「9/1」になってどの点がどの足かを特定できなかった(実データで
71
+ * `head_and_shoulders` / `triple_top` の 2 例で再現)。本文側
72
+ * (`detectPatternsViewsHandler.ts` の `toDateOrTime`)は既に時刻まで出しており、
73
+ * 構造図だけが取り残されていた。`src/schema/patterns.ts` の `tz` description は
74
+ * 構造図を明示的に対象へ含めているので、契約側は元から時刻表示を約束している。
75
+ *
76
+ * - intraday: `M/D HH:mm`
77
+ * - 日足以上 / `type` 未指定: `M/D`(従来どおり。表示形式を変えない)
78
+ *
79
+ * 時間足の分類は `lib/datetime.ts` の `isIntradayType` を使う(本文側と同一実装。
80
+ * ここで集合を持ち直すと 2 箇所が黙ってずれる)。
81
+ */
82
+ function formatDateTime(iso: string | undefined, tz: string | undefined, type: string | undefined): string {
83
+ if (!iso) return '';
84
+ const short = formatDateShort(iso, tz);
85
+ if (!type || !isIntradayType(type)) return short;
86
+ const ms = Date.parse(iso);
87
+ if (!Number.isFinite(ms)) return short;
88
+ const withTz = toIsoWithTz(ms, resolveTz(tz)); // 'YYYY-MM-DDTHH:mm:ss'
89
+ return withTz ? `${short} ${withTz.slice(11, 16)}` : short;
90
+ }
91
+
92
+ /**
93
+ * `artifact.identifier` 専用。**tz を通さない**(issue #200: identifier は表示ではなく
94
+ * 成果物の ID なので、tz 対応で値を変えるとスナップショット等が動く。触らないこと)。
95
+ */
56
96
  function formatDateIsoShort(iso?: string): string {
57
97
  if (!iso) return '';
58
98
  return String(iso).split('T')[0] || String(iso);
59
99
  }
60
100
 
101
+ /**
102
+ * パターン構造図(SVG)を生成する。
103
+ *
104
+ * `neckline.price` は**呼び出し側が持っているネックライン水準そのもの**を渡す。図の側で
105
+ * 構成点から再計算してはいけない(issue #226)。relaxed H&S / 逆 H&S は 2 定義点の平均ではなく
106
+ * **ブレイク判定(`findHsBreakoutIdx`)に渡す水平線の y** をネックラインとして持っており、
107
+ * 再計算すると同じ 1 件の出力の中で**構造図だけ**が content 本文行・ターゲット・ブレイク判定と
108
+ * 食い違う(実測で 27,364 円のずれ)。
109
+ *
110
+ * `triple_top` / `triple_bottom` は今も `pivots[1]` / `pivots[3]` の平均を再計算しているが、
111
+ * 呼び出し側(`detect_triples.ts`)が渡す `nlAvg` がまさにその平均で、**渡し値と再計算値が
112
+ * 一致している**ため食い違いは起きない。本 issue の範囲外として据え置く。
113
+ */
61
114
  export function generatePatternDiagram(
62
115
  patternType: string,
63
116
  pivots: Array<{ idx: number; price: number; kind: 'H' | 'L'; date?: string }>,
64
117
  neckline: { price: number },
65
118
  range: { start: string; end: string },
66
- options?: { isForming?: boolean },
119
+ options?: { isForming?: boolean; tz?: string; type?: string },
67
120
  ): PatternDiagramData {
121
+ // tz 対応方式(issue #200 要件 F-2、2 案のうち (a) を選択):
122
+ // 検出層(detect_doubles / detect_triples / detect_hs / detect_wedges)は既に
123
+ // `DetectContext` 経由でスキャン共通値(sizeThresholds 等)を 1 箇所解決して各検出器に
124
+ // 配っており、tz もそれに倣って `ctx.tz` を通すだけで済む(呼び出し側の追加実装が
125
+ // `{ tz: ctx.tz }` を足すだけで、判定ロジックは 1 行も変わらない)。
126
+ // (b)(図側に生 ISO を持たせ、整形をハンドラ側に寄せる)は `PatternDiagramData` の形を
127
+ // 変える必要があり、SVG 文字列は生成時に日付を焼き込む構造(テンプレートリテラル)なので、
128
+ // 整形をハンドラ側に遅延するには SVG 生成そのものを検出時から表示時に移す作り替えが要る。
129
+ // (a) は既存の `PatternDiagramData` / `structureDiagram` スキーマを一切変えずに直せるため、
130
+ // こちらを採用した。
131
+ const tz = options?.tz;
132
+ // 時間足(issue #233)。intraday のときだけラベルに時刻(HH:mm)を足すための表示専用値で、
133
+ // 図の形状・座標・ネックライン計算には一切使わない。`tz` と同じく `ctx.type` を配線するだけ。
134
+ // 未指定時は従来どおり `M/D` になるので、渡さない呼び出し元の出力は 1 バイトも変わらない。
135
+ const type = options?.type;
68
136
  const startDate = formatDateIsoShort(range.start);
69
137
  const identifier = `${patternType}-diagram-${startDate}`;
70
- const title = `${getPatternLabel(patternType)}構造図 (${formatDateShort(range.start)}-${formatDateShort(range.end)})`;
138
+ const title = `${getPatternLabel(patternType)}構造図 (${formatDateTime(range.start, tz, type)}-${formatDateTime(range.end, tz, type)})`;
71
139
  const dashed = options?.isForming ? '5,5' : '';
72
140
 
73
141
  if (patternType === 'double_bottom') {
@@ -76,9 +144,9 @@ export function generatePatternDiagram(
76
144
  const pk = pivots.find((p) => p.kind === 'H');
77
145
  const rest = pivots.filter((p) => p.kind === 'L' && p !== v1);
78
146
  const v2 = rest.length ? rest[0] : undefined;
79
- const valley1Date = formatDateShort(v1?.date);
80
- const peakDate = formatDateShort(pk?.date);
81
- const valley2Date = formatDateShort(v2?.date);
147
+ const valley1Date = formatDateTime(v1?.date, tz, type);
148
+ const peakDate = formatDateTime(pk?.date, tz, type);
149
+ const valley2Date = formatDateTime(v2?.date, tz, type);
82
150
  const necklinePrice = Math.round(neckline.price).toLocaleString('ja-JP');
83
151
  const svg = `<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
84
152
  <rect width="600" height="300" fill="#f8f9fa"/>
@@ -93,7 +161,7 @@ export function generatePatternDiagram(
93
161
  <text x="250" y="80" text-anchor="middle" fill="#333" font-size="14">山: ${peakDate}</text>
94
162
  <circle cx="350" cy="250" r="6" fill="#3b82f6"/>
95
163
  <text x="350" y="280" text-anchor="middle" fill="#333" font-size="14">谷: ${valley2Date}</text>
96
- <text x="300" y="30" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateShort(range.start)}-${formatDateShort(range.end)})</text>
164
+ <text x="300" y="30" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateTime(range.start, tz, type)}-${formatDateTime(range.end, tz, type)})</text>
97
165
  </svg>`;
98
166
  return { svg, artifact: { identifier, title } };
99
167
  }
@@ -104,9 +172,9 @@ export function generatePatternDiagram(
104
172
  const vl = pivots.find((p) => p.kind === 'L');
105
173
  const rest = pivots.filter((p) => p.kind === 'H' && p !== p1);
106
174
  const p2 = rest.length ? rest[0] : undefined;
107
- const peak1Date = formatDateShort(p1?.date);
108
- const valleyDate = formatDateShort(vl?.date);
109
- const peak2Date = formatDateShort(p2?.date);
175
+ const peak1Date = formatDateTime(p1?.date, tz, type);
176
+ const valleyDate = formatDateTime(vl?.date, tz, type);
177
+ const peak2Date = formatDateTime(p2?.date, tz, type);
110
178
  const necklinePrice = Math.round(neckline.price).toLocaleString('ja-JP');
111
179
  const svg = `<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
112
180
  <rect width="600" height="300" fill="#f8f9fa"/>
@@ -121,7 +189,7 @@ export function generatePatternDiagram(
121
189
  <text x="250" y="235" text-anchor="middle" fill="#333" font-size="14">谷: ${valleyDate}</text>
122
190
  <circle cx="350" cy="70" r="6" fill="#3b82f6"/>
123
191
  <text x="350" y="55" text-anchor="middle" fill="#333" font-size="14">山: ${peak2Date}</text>
124
- <text x="300" y="30" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateShort(range.start)}-${formatDateShort(range.end)})</text>
192
+ <text x="300" y="30" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateTime(range.start, tz, type)}-${formatDateTime(range.end, tz, type)})</text>
125
193
  </svg>`;
126
194
  return { svg, artifact: { identifier, title } };
127
195
  }
@@ -133,13 +201,16 @@ export function generatePatternDiagram(
133
201
  const head = pivots[2];
134
202
  const peak2 = pivots[3];
135
203
  const rightShoulder = pivots[4];
136
- const lsDate = formatDateShort(leftShoulder?.date);
137
- const p1Date = formatDateShort(peak1?.date);
138
- const headDate = formatDateShort(head?.date);
139
- const p2Date = formatDateShort(peak2?.date);
140
- const rsDate = formatDateShort(rightShoulder?.date);
141
- // ネックライン: 山1/山2の平均価格(表示用)
142
- const nlVal = ((peak1?.price ?? 0) + (peak2?.price ?? 0)) / 2;
204
+ const lsDate = formatDateTime(leftShoulder?.date, tz, type);
205
+ const p1Date = formatDateTime(peak1?.date, tz, type);
206
+ const headDate = formatDateTime(head?.date, tz, type);
207
+ const p2Date = formatDateTime(peak2?.date, tz, type);
208
+ const rsDate = formatDateTime(rightShoulder?.date, tz, type);
209
+ // ネックライン水準は呼び出し側の値をそのまま出す(issue #226。上の docstring を参照)。
210
+ // strict 経路は `(peak1 + peak2) / 2` を渡してくるので、この経路の出力は 1 バイトも変わらない。
211
+ // **SVG 内の `<!-- Neckline (peaks average) -->` は据え置く**——strict の SVG を byte 単位で
212
+ // 不変に保つため(#226 の受け入れ条件)。relaxed では「平均」ではなく水平線の y になる。
213
+ const nlVal = neckline.price;
143
214
  const necklinePrice = Math.round(nlVal).toLocaleString('ja-JP');
144
215
  const svg = `<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
145
216
  <rect width="600" height="300" fill="#f8f9fa"/>
@@ -162,7 +233,7 @@ export function generatePatternDiagram(
162
233
  <text x="400" y="65" text-anchor="middle" fill="#333" font-size="14">山2: ${p2Date}</text>
163
234
  <circle cx="500" cy="180" r="6" fill="#3b82f6"/>
164
235
  <text x="500" y="205" text-anchor="middle" fill="#333" font-size="14">右肩: ${rsDate}</text>
165
- <text x="300" y="20" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateShort(range.start)}-${formatDateShort(range.end)})</text>
236
+ <text x="300" y="20" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateTime(range.start, tz, type)}-${formatDateTime(range.end, tz, type)})</text>
166
237
  </svg>`;
167
238
  return { svg, artifact: { identifier, title } };
168
239
  }
@@ -174,13 +245,15 @@ export function generatePatternDiagram(
174
245
  const head = pivots[2];
175
246
  const valley2 = pivots[3];
176
247
  const rightShoulder = pivots[4];
177
- const lsDate = formatDateShort(leftShoulder?.date);
178
- const v1Date = formatDateShort(valley1?.date);
179
- const headDate = formatDateShort(head?.date);
180
- const v2Date = formatDateShort(valley2?.date);
181
- const rsDate = formatDateShort(rightShoulder?.date);
182
- // ネックライン: 谷1/谷2の平均価格(表示用)
183
- const nlVal = ((valley1?.price ?? 0) + (valley2?.price ?? 0)) / 2;
248
+ const lsDate = formatDateTime(leftShoulder?.date, tz, type);
249
+ const v1Date = formatDateTime(valley1?.date, tz, type);
250
+ const headDate = formatDateTime(head?.date, tz, type);
251
+ const v2Date = formatDateTime(valley2?.date, tz, type);
252
+ const rsDate = formatDateTime(rightShoulder?.date, tz, type);
253
+ // ネックライン水準は呼び出し側の値をそのまま出す(issue #226。上の docstring を参照)。
254
+ // strict 経路は `(valley1 + valley2) / 2` を渡してくるので、この経路の出力は 1 バイトも変わらない。
255
+ // **SVG 内の `<!-- Neckline (valleys average) -->` は据え置く**——理由は逆 H&S 側と同じ。
256
+ const nlVal = neckline.price;
184
257
  const necklinePrice = Math.round(nlVal).toLocaleString('ja-JP');
185
258
  const svg = `<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
186
259
  <rect width="600" height="300" fill="#f8f9fa"/>
@@ -203,7 +276,7 @@ export function generatePatternDiagram(
203
276
  <text x="400" y="245" text-anchor="middle" fill="#333" font-size="14">谷2: ${v2Date}</text>
204
277
  <circle cx="500" cy="120" r="6" fill="#3b82f6"/>
205
278
  <text x="500" y="105" text-anchor="middle" fill="#333" font-size="14">右肩: ${rsDate}</text>
206
- <text x="300" y="20" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateShort(range.start)}-${formatDateShort(range.end)})</text>
279
+ <text x="300" y="20" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateTime(range.start, tz, type)}-${formatDateTime(range.end, tz, type)})</text>
207
280
  </svg>`;
208
281
  return { svg, artifact: { identifier, title } };
209
282
  }
@@ -215,11 +288,11 @@ export function generatePatternDiagram(
215
288
  const valley2 = pivots[2];
216
289
  const peak2 = pivots[3];
217
290
  const valley3 = pivots[4];
218
- const v1Date = formatDateShort(valley1?.date);
219
- const p1Date = formatDateShort(peak1?.date);
220
- const v2Date = formatDateShort(valley2?.date);
221
- const p2Date = formatDateShort(peak2?.date);
222
- const v3Date = formatDateShort(valley3?.date);
291
+ const v1Date = formatDateTime(valley1?.date, tz, type);
292
+ const p1Date = formatDateTime(peak1?.date, tz, type);
293
+ const v2Date = formatDateTime(valley2?.date, tz, type);
294
+ const p2Date = formatDateTime(peak2?.date, tz, type);
295
+ const v3Date = formatDateTime(valley3?.date, tz, type);
223
296
  const nlVal = ((peak1?.price ?? 0) + (peak2?.price ?? 0)) / 2;
224
297
  const necklinePrice = Math.round(nlVal).toLocaleString('ja-JP');
225
298
  const svg = `<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
@@ -238,7 +311,7 @@ export function generatePatternDiagram(
238
311
  <circle cx="250" cy="250" r="6" fill="#3b82f6"/><text x="250" y="275" text-anchor="middle" fill="#333" font-size="14">谷2: ${v2Date}</text>
239
312
  <circle cx="335" cy="120" r="6" fill="#3b82f6"/><text x="335" y="105" text-anchor="middle" fill="#333" font-size="14">山2: ${p2Date}</text>
240
313
  <circle cx="420" cy="250" r="6" fill="#3b82f6"/><text x="420" y="275" text-anchor="middle" fill="#333" font-size="14">谷3: ${v3Date}</text>
241
- <text x="300" y="20" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateShort(range.start)}-${formatDateShort(range.end)})</text>
314
+ <text x="300" y="20" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateTime(range.start, tz, type)}-${formatDateTime(range.end, tz, type)})</text>
242
315
  </svg>`;
243
316
  return { svg, artifact: { identifier, title } };
244
317
  }
@@ -250,11 +323,11 @@ export function generatePatternDiagram(
250
323
  const peak2 = pivots[2];
251
324
  const valley2 = pivots[3];
252
325
  const peak3 = pivots[4];
253
- const p1Date = formatDateShort(peak1?.date);
254
- const v1Date = formatDateShort(valley1?.date);
255
- const p2Date = formatDateShort(peak2?.date);
256
- const v2Date = formatDateShort(valley2?.date);
257
- const p3Date = formatDateShort(peak3?.date);
326
+ const p1Date = formatDateTime(peak1?.date, tz, type);
327
+ const v1Date = formatDateTime(valley1?.date, tz, type);
328
+ const p2Date = formatDateTime(peak2?.date, tz, type);
329
+ const v2Date = formatDateTime(valley2?.date, tz, type);
330
+ const p3Date = formatDateTime(peak3?.date, tz, type);
258
331
  const nlVal = ((valley1?.price ?? 0) + (valley2?.price ?? 0)) / 2;
259
332
  const necklinePrice = Math.round(nlVal).toLocaleString('ja-JP');
260
333
  const svg = `<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
@@ -273,7 +346,7 @@ export function generatePatternDiagram(
273
346
  <circle cx="250" cy="80" r="6" fill="#3b82f6"/><text x="250" y="65" text-anchor="middle" fill="#333" font-size="14">山2: ${p2Date}</text>
274
347
  <circle cx="335" cy="210" r="6" fill="#3b82f6"/><text x="335" y="235" text-anchor="middle" fill="#333" font-size="14">谷2: ${v2Date}</text>
275
348
  <circle cx="420" cy="80" r="6" fill="#3b82f6"/><text x="420" y="65" text-anchor="middle" fill="#333" font-size="14">山3: ${p3Date}</text>
276
- <text x="300" y="20" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateShort(range.start)}-${formatDateShort(range.end)})</text>
349
+ <text x="300" y="20" text-anchor="middle" fill="#111" font-size="14">${getPatternLabel(patternType)} (${formatDateTime(range.start, tz, type)}-${formatDateTime(range.end, tz, type)})</text>
277
350
  </svg>`;
278
351
  return { svg, artifact: { identifier, title } };
279
352
  }
@@ -281,8 +354,8 @@ export function generatePatternDiagram(
281
354
  if (patternType === 'falling_wedge') {
282
355
  // テンプレート図(600x300)。上側/下側の収束ライン、主要タッチ、アペックス、上抜け矢印を描画
283
356
  // 傾きや位置はサンプル配置(視覚的分かりやすさ優先)
284
- const startShort = formatDateShort(range.start);
285
- const endShort = formatDateShort(range.end);
357
+ const startShort = formatDateTime(range.start, tz, type);
358
+ const endShort = formatDateTime(range.end, tz, type);
286
359
  // 主要タッチポイント(間引き想定、固定配置)
287
360
  const touchPoints = [
288
361
  { x: 100, y: 80 },
@@ -321,8 +394,8 @@ export function generatePatternDiagram(
321
394
 
322
395
  if (patternType === 'rising_wedge') {
323
396
  // テンプレート図(600x300)。上側/下側の収束ライン、主要タッチ、アペックス、下抜け矢印を描画
324
- const startShort = formatDateShort(range.start);
325
- const endShort = formatDateShort(range.end);
397
+ const startShort = formatDateTime(range.start, tz, type);
398
+ const endShort = formatDateTime(range.end, tz, type);
326
399
  const touchPoints = [
327
400
  { x: 100, y: 240 },
328
401
  { x: 200, y: 220 },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bitbank-lab-mcp",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Experimental MCP server for bitbank — botters lab community edition. Market data, technical analysis, charting, and Private API trading tools.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,9 +41,9 @@
41
41
  "ci:typecheck": "npm run gen:types && tsc --noEmit -p tsconfig.json",
42
42
  "build": "npm run ci:typecheck",
43
43
  "gen:types": "tsx scripts/gen_types.ts",
44
- "lint": "oxlint src/ tools/ lib/",
45
- "lint:fix": "oxlint --fix src/ tools/ lib/",
46
- "format": "biome format --write src/ tools/ lib/",
44
+ "lint": "oxlint src/ tools/ lib/ tests/",
45
+ "lint:fix": "oxlint --fix src/ tools/ lib/ tests/",
46
+ "format": "biome format --write src/ tools/ lib/ tests/",
47
47
  "postinstall": "mkdir -p assets && cp node_modules/lightweight-charts/dist/lightweight-charts.standalone.production.js assets/lightweight-charts.standalone.js || true",
48
48
  "prepack": "npm run gen:types && npm run postinstall",
49
49
  "build:ui:cancel": "vite build --config ui/cancel-confirm/vite.config.ts"
@@ -79,7 +79,7 @@
79
79
  "@types/react": "^19.2.14",
80
80
  "@types/react-dom": "^19.2.3",
81
81
  "@vitejs/plugin-react": "^6.0.1",
82
- "@vitest/coverage-v8": "^4.1.2",
82
+ "@vitest/coverage-v8": "^4.1.11",
83
83
  "lefthook": "^2.1.4",
84
84
  "nanoid": "^3.3.18",
85
85
  "oxlint": "^1.55.0",
@@ -88,6 +88,6 @@
88
88
  "typescript": "^6.0.3",
89
89
  "vite": "^8.0.10",
90
90
  "vite-plugin-singlefile": "^2.3.3",
91
- "vitest": "^4.0.18"
91
+ "vitest": "^4.1.11"
92
92
  }
93
93
  }