feat(data): extend market data provider with charts, fundamentals, and quant analysis

Adds a stock data cache layer and indicator helpers (MA/RSI/MACD), expands
the MarketDataProvider interface with candles, fundamentals, related-data,
and quant analysis, and threads tags + source attribution through the
shared types. Updates affected agent tests.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 23:20:42 +08:00
parent 6092675f8d
commit 870b9cb2b1
12 changed files with 2187 additions and 32 deletions

View File

@@ -10,7 +10,7 @@ export class WatchlistStore {
return this.read();
}
async add(symbolInput: string, name?: string): Promise<WatchStock> {
async add(symbolInput: string, name?: string, tags: string[] = []): Promise<WatchStock> {
const normalized = normalizeSymbol(symbolInput);
const stocks = await this.read();
const existing = stocks.find((stock) => stock.display === normalized.display);
@@ -22,12 +22,26 @@ export class WatchlistStore {
...normalized,
id: normalized.display,
name: name?.trim() || undefined,
tags: normalizeTags(tags),
addedAt: new Date().toISOString()
};
await this.write([...stocks, stock]);
return stock;
}
async updateTags(symbolInput: string, tags: string[]): Promise<WatchStock> {
const normalized = normalizeSymbol(symbolInput);
const stocks = await this.read();
const stock = stocks.find((item) => item.display === normalized.display);
if (!stock) {
throw new Error("Stock is not in watchlist");
}
const updated = { ...stock, tags: normalizeTags(tags) };
await this.write(stocks.map((item) => (item.display === normalized.display ? updated : item)));
return updated;
}
async remove(symbolInput: string): Promise<void> {
const normalized = normalizeSymbol(symbolInput);
const stocks = await this.read();
@@ -38,7 +52,20 @@ export class WatchlistStore {
try {
const content = await readFile(this.path, "utf8");
const parsed = JSON.parse(content) as WatchStock[];
return Array.isArray(parsed) ? parsed : [];
if (!Array.isArray(parsed)) {
return [];
}
const byDisplay = new Map<string, WatchStock>();
for (const stock of parsed) {
const normalized = normalizeSymbol(stock.display ?? stock.symbol);
byDisplay.set(normalized.display, {
...stock,
...normalized,
id: normalized.display,
tags: normalizeTags(stock.tags ?? [])
});
}
return Array.from(byDisplay.values());
} catch (error) {
if (isMissingFile(error)) {
return [];
@@ -56,3 +83,14 @@ export class WatchlistStore {
function isMissingFile(error: unknown): boolean {
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
}
function normalizeTags(tags: string[]): string[] {
return Array.from(
new Set(
tags
.map((tag) => tag.trim())
.filter(Boolean)
.map((tag) => tag.slice(0, 24))
)
).slice(0, 8);
}