watch_add
Add stocks to your watchlist by specifying code, name, market, and reason for tracking. Monitor A-shares, Hong Kong, and US stocks for informed investment decisions.
Instructions
添加观察股票
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | 股票代码 | |
| name | Yes | 股票名称 | |
| reason | Yes | 观察理由或目标 | |
| market | Yes | 市场 |
Implementation Reference
- src/watch.ts:26-52 (handler)The core implementation of addWatch function that adds a stock to the watch list. It loads existing data, checks for duplicates, creates a new WatchItem with timestamp, saves to watch.json file, and returns the new item.export function addWatch( code: string, name: string, reason: string, market: Market ): WatchItem { const watchList = loadWatchList(); // 检查是否已存在 const exists = watchList.some(item => item.code === code && item.market === market); if (exists) { throw new Error('Stock already in watch list'); } const newItem: WatchItem = { code, name, reason, market, createdAt: new Date().toISOString(), }; watchList.push(newItem); saveWatchList(watchList); return newItem; }
- src/index.ts:392-408 (handler)The MCP tool handler for watch_add that parses input arguments using AddWatchSchema, calls watch.addWatch() function with the parameters, and returns the result as formatted JSON.if (name === 'watch_add') { const params = AddWatchSchema.parse(args); const result = watch.addWatch( params.code, params.name, params.reason, params.market as Market ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:204-217 (registration)Tool registration for watch_add defining its name, description, input schema properties (code, name, reason, market), and required fields.{ name: 'watch_add', description: '添加观察股票', inputSchema: { type: 'object', properties: { code: { type: 'string', description: '股票代码' }, name: { type: 'string', description: '股票名称' }, reason: { type: 'string', description: '观察理由或目标' }, market: { type: 'string', enum: ['sh', 'sz', 'hk', 'us'], description: '市场' }, }, required: ['code', 'name', 'reason', 'market'], }, },
- src/index.ts:53-58 (schema)Zod schema definition (AddWatchSchema) for input validation with required fields: code (string), name (string), reason (string), and market (enum: sh, sz, hk, us).const AddWatchSchema = z.object({ code: z.string().describe('股票代码'), name: z.string().describe('股票名称'), reason: z.string().describe('观察理由或目标'), market: z.enum(['sh', 'sz', 'hk', 'us']).describe('市场'), });
- src/types.ts:93-99 (schema)Type definition for WatchItem interface defining the structure of watch list items with code, name, reason, market, and createdAt fields.export interface WatchItem { code: string; name: string; reason: string; market: Market; createdAt: string; }