Skip to main content
Glama
Xxx00xxX33

FinanceMCP

by Xxx00xxX33

dragon_tiger_inst

Retrieve institutional trading details from Dragon Tiger Board for specific dates. Provides buy/sell/net amounts and listing reasons to analyze major institutional transactions.

Instructions

龙虎榜机构成交明细(top_inst)。必填:交易日期;可选:股票TS代码。返回表格包含买入/卖出/净额及上榜理由等。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
trade_dateYes交易日期,格式YYYYMMDD
ts_codeNo可选,股票TS代码,如 000001.SZ

Implementation Reference

  • The core handler function 'run' that fetches dragon tiger list institutional trading details from Tushare API 'top_inst', processes data into a markdown table with totals and stock code explanations.
    async run(args: { trade_date: string; ts_code?: string }) {
      try {
        if (!args.trade_date || args.trade_date.trim().length !== 8) {
          throw new Error('trade_date 必须为YYYYMMDD');
        }
    
        if (!TUSHARE_CONFIG.API_TOKEN) {
          throw new Error('请配置TUSHARE_TOKEN环境变量');
        }
    
        const params: any = {
          api_name: 'top_inst',
          token: TUSHARE_CONFIG.API_TOKEN,
          params: {
            trade_date: args.trade_date
          }
        };
        if (args.ts_code) params.params.ts_code = args.ts_code;
    
        const controller = new AbortController();
        const timeoutId = setTimeout(() => controller.abort(), TUSHARE_CONFIG.TIMEOUT);
        try {
          const resp = await fetch(TUSHARE_CONFIG.API_URL, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(params),
            signal: controller.signal
          });
          if (!resp.ok) throw new Error(`Tushare API请求失败: ${resp.status}`);
          const data = await resp.json();
          if (data.code !== 0) throw new Error(`Tushare API错误: ${data.msg}`);
    
          const fields: string[] = data.data?.fields ?? [];
          const items: any[] = data.data?.items ?? [];
          if (items.length === 0) {
            return {
              content: [
                { type: 'text', text: `# 龙虎榜机构明细 ${args.trade_date}${args.ts_code ? ` - ${args.ts_code}` : ''}\n\n暂无数据` }
              ]
            };
          }
    
          // 字段顺序按需求固定(移除 trade_date 列)
          const desired = ['ts_code','exalter','buy','buy_rate','sell','sell_rate','net_buy','reason'];
          const headers = desired.filter(h => fields.includes(h));
    
          let table = `| ${headers.join(' | ')} |\n`;
          table += `|${headers.map(() => '--------').join('|')}|\n`;
          let totalBuy = 0;
          let totalSell = 0;
          let totalNet = 0;
          for (const row of items) {
            const obj: Record<string, any> = {};
            fields.forEach((f: string, idx: number) => obj[f] = row[idx]);
            const line = headers.map(h => {
              const v = obj[h];
              return (v === null || v === undefined || v === '') ? 'N/A' : String(v);
            });
            table += `| ${line.join(' | ')} |\n`;
            const buyVal = Number(obj.buy);
            const sellVal = Number(obj.sell);
            const netVal = Number(obj.net_buy);
            if (!isNaN(buyVal)) totalBuy += buyVal;
            if (!isNaN(sellVal)) totalSell += sellVal;
            if (!isNaN(netVal)) totalNet += netVal;
          }
    
          const title = `# 龙虎榜机构明细 ${args.trade_date}${args.ts_code ? ` - ${args.ts_code}` : ''}`;
          const fmt = (n: number) => n.toLocaleString('zh-CN', { maximumFractionDigits: 2 });
          const summary = `\n\n## 当日资金统计\n- 买入额合计: ${fmt(totalBuy)} 元\n- 卖出额合计: ${fmt(totalSell)} 元\n- 净流入: ${fmt(totalNet)} 元`;
          
          // 收集所有股票代码并生成说明
          const stockCodes: string[] = [];
          for (const row of items) {
            const obj: Record<string, any> = {};
            fields.forEach((f: string, idx: number) => obj[f] = row[idx]);
            if (obj.ts_code) {
              stockCodes.push(String(obj.ts_code));
            }
          }
          const stockExplanation = await resolveStockCodes(stockCodes);
          
          return { content: [ { type: 'text', text: `${title}\n\n${table}${summary}${stockExplanation}` } ] };
        } finally {
          clearTimeout(timeoutId);
        }
      } catch (error) {
        return {
          content: [ { type: 'text', text: `❌ 查询失败: ${error instanceof Error ? error.message : String(error)}` } ],
          isError: true
        };
      }
    }
  • Input schema definition for the dragon_tiger_inst tool, specifying trade_date as required and ts_code as optional.
    parameters: {
      type: 'object',
      properties: {
        trade_date: {
          type: 'string',
          description: '交易日期,格式YYYYMMDD'
        },
        ts_code: {
          type: 'string',
          description: '可选,股票TS代码,如 000001.SZ'
        }
      },
      required: ['trade_date']
    },
  • src/index.ts:252-255 (registration)
    Tool registration in the main tools list for MCP stdio server.
      name: dragonTigerInst.name,
      description: dragonTigerInst.description,
      inputSchema: dragonTigerInst.parameters
    }
  • src/index.ts:395-398 (registration)
    Dispatch case in the main request handler for executing dragon_tiger_inst tool.
    case "dragon_tiger_inst": {
      const trade_date = String(request.params.arguments?.trade_date);
      const ts_code = request.params.arguments?.ts_code ? String(request.params.arguments.ts_code) : undefined;
      return normalizeResult(await dragonTigerInst.run({ trade_date, ts_code }));
  • Tool registration in the toolList array for HTTP server.
    { name: dragonTigerInst.name, description: dragonTigerInst.description, inputSchema: dragonTigerInst.parameters },

Latest Blog Posts

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/Xxx00xxX33/FinanceMCP'

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