Skip to main content
Glama

MCP Stock Assistant

formatters.ts3.38 kB
import type { HistoryDataPoint, IndexData, StockData } from "./types.js"; function formatPrice(price: number): string { return price.toFixed(2); } function formatVolume(volume: number): string { return volume.toFixed(2); } export function formatHistoryData(data: HistoryDataPoint[], stockName: string): string { let result = ` 📈 ${stockName} 历史数据 (最近${data.length}个交易日) `; const recentData = data.slice(0, Math.min(10, data.length)); result += "日期 开盘 收盘 最高 最低 成交量(手) 涨跌幅\n"; result += "─".repeat(65) + "\n"; for (const point of recentData) { const changeColor = point.changePercent >= 0 ? "📈" : "📉"; result += `${point.date} ${formatPrice(point.open).padStart(6)} ${formatPrice(point.close).padStart(6)} ${formatPrice(point.high).padStart(6)} ${formatPrice(point.low).padStart(6)} ${formatVolume(point.volume).padStart(8)} ${changeColor}${point.changePercent.toFixed(2)}%\n`; } const prices = data.map(d => d.close); const maxPrice = Math.max(...prices); const minPrice = Math.min(...prices); const avgPrice = prices.reduce((a, b) => a + b, 0) / prices.length; const totalVolume = data.reduce((sum, d) => sum + d.volume, 0); result += `\n📊 统计信息: 最高价: ${formatPrice(maxPrice)} 最低价: ${formatPrice(minPrice)} 平均价: ${formatPrice(avgPrice)} 总成交量: ${formatVolume(totalVolume)}手 `; return result; } export function formatIndexInfo(data: IndexData[]): string { let result = ` 📊 大盘指数信息 `; result += "指数名称 当前点位 涨跌幅 涨跌点 成交量(手) 成交额(万)\n"; result += "─".repeat(70) + "\n"; for (const index of data) { const changeColor = index.changePercent >= 0 ? "📈" : "📉"; const changeSign = index.change >= 0 ? "+" : ""; result += `${index.name.padEnd(10)} ${formatPrice(index.price).padStart(8)} ${changeColor}${index.changePercent.toFixed(2)}%`.padEnd(20); result += ` ${changeSign}${formatPrice(index.change).padStart(7)} ${formatVolume(index.volume).padStart(10)} ${formatVolume(index.amount).padStart(10)}\n`; } result += `\n🕐 更新时间: ${data[0]?.time || new Date().toLocaleTimeString()}`; return result; } export function formatStockInfo(data: StockData): string { let result = ` 股票信息: ${data.code} (${data.name}) 当前价格: ${formatPrice(data.price)} ${ data.change >= 0 ? `涨幅: +${data.changePercent}%` : `跌幅: ${data.changePercent}%` } 涨跌额: ${data.change > 0 ? "+" : ""}${formatPrice(data.change)} 开盘价: ${formatPrice(data.open)} 最高价: ${formatPrice(data.high)} 最低价: ${formatPrice(data.low)} 昨收价: ${formatPrice(data.lastClose)} 成交量: ${formatVolume(data.volume)}手 成交额: ${formatVolume(data.amount)}万 换手率: ${data.turnoverRate}% 市盈率(动态): ${data.peRatio} 振幅: ${data.amplitude}% 更新时间: ${data.time} 买卖盘口: `; for (let i = 4; i >= 0; i--) { const order = data.sellOrders[i]; result += `卖${i + 1}: ${formatPrice(order.price)} / ${formatVolume( order.volume )}手\n`; } for (let i = 0; i < 5; i++) { const order = data.buyOrders[i]; result += `买${i + 1}: ${formatPrice(order.price)} / ${formatVolume( order.volume )}手\n`; } return result; }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/qqzhangyanhua/mcp-stock'

If you have feedback or need assistance with the MCP directory API, please join our Discord server