Skip to main content
Glama
Cognitive-Stack

Volume Wall Detector MCP

analyze-stock

Analyzes stock trading data to identify significant price levels using volume and value metrics. Input a stock symbol and optional days to track volume walls and distribution patterns.

Instructions

Analyze stock data including volume and value analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
daysNoNumber of days to analyze (optional)
symbolYesStock symbol to analyze

Implementation Reference

  • Main handler function that executes the 'analyze-stock' tool logic: fetches order book and trades, computes volume walls analysis, and returns structured stock data analysis.
    export const analyzeVolumeWalls = async (symbol: string, days?: number) => {
      const orderBook = await getLatestOrderBook(symbol);
      if (!orderBook) {
        throw new Error("No order book data available");
      }
      
      const trades = await getRecentTrades(symbol, config.TRADES_TO_FETCH, days);
      const priceVolumes = analyzeVolumeAtPrice(trades, orderBook);
      
      // Sort by total value
      const sortedLevels = Object.entries(priceVolumes)
        .sort(([, a], [, b]) => b.total_value - a.total_value)
        .slice(0, 5);
        
      // Calculate trading summaries
      const buyVolume = trades
        .filter(t => t.side === "bu")
        .reduce((sum, t) => sum + t.volume, 0);
        
      const sellVolume = trades
        .filter(t => t.side === "sd")
        .reduce((sum, t) => sum + t.volume, 0);
        
      const afterHourTrades = trades.filter(t => t.side === "after-hour");
      const afterHourBuy = afterHourTrades
        .filter(t => t.price >= orderBook.ask_1.price)
        .reduce((sum, t) => sum + t.volume, 0);
        
      const afterHourSell = afterHourTrades
        .filter(t => t.price <= orderBook.bid_1.price)
        .reduce((sum, t) => sum + t.volume, 0);
        
      const afterHourUnknown = afterHourTrades
        .filter(t => orderBook.bid_1.price < t.price && t.price < orderBook.ask_1.price)
        .reduce((sum, t) => sum + t.volume, 0);
        
      const totalVolume = buyVolume + sellVolume + afterHourBuy + afterHourSell + afterHourUnknown;
      
      return {
        timestamp: orderBook.timestamp,
        symbol,
        market_status: {
          current_price: orderBook.match_price,
          bid_price: orderBook.bid_1.price,
          bid_volume: orderBook.bid_1.volume,
          ask_price: orderBook.ask_1.price,
          ask_volume: orderBook.ask_1.volume,
          spread: orderBook.ask_1.price - orderBook.bid_1.price
        },
        volume_analysis: {
          significant_levels: sortedLevels.map(([price, data]) => ({
            price: Number(price),
            ...data
          })),
          current_bid_accumulated: priceVolumes[orderBook.bid_1.price] || {},
          current_ask_accumulated: priceVolumes[orderBook.ask_1.price] || {}
        },
        trading_summary: {
          period: `last ${config.TRADES_TO_FETCH} trades`,
          total_trades: trades.length,
          volume: {
            buy: buyVolume,
            sell: sellVolume,
            after_hour: {
              buy: afterHourBuy,
              sell: afterHourSell,
              unknown: afterHourUnknown,
              total: afterHourBuy + afterHourSell + afterHourUnknown
            },
            total: totalVolume,
            buy_ratio: (buyVolume + afterHourBuy) / 
              (buyVolume + sellVolume + afterHourBuy + afterHourSell) || 0
          }
        }
      };
    }; 
  • Tool registration defining name, description, input schema with Zod, and execute function delegating to analyzeVolumeWalls.
    {
      name: "analyze-stock",
      description: "Analyze stock data including volume and value analysis",
      parameters: z.object({
        symbol: z.string().describe("Stock symbol to analyze"),
        days: z.number().optional().describe("Number of days to analyze (optional)")
      }),
      execute: async (args) => {
        const result = await analyzeVolumeWalls(args.symbol, args.days);
        return JSON.stringify(result);
      }
    }
  • Zod schema for input parameters: symbol (required string), days (optional number).
    parameters: z.object({
      symbol: z.string().describe("Stock symbol to analyze"),
      days: z.number().optional().describe("Number of days to analyze (optional)")
    }),
  • Supporting helper function that analyzes volume and value at specific price levels from trades and order book data.
    export const analyzeVolumeAtPrice = (
      trades: Trade[],
      orderBook: OrderBook
    ): Record<number, PriceVolumeData> => {
      const priceVolumes: Record<number, PriceVolumeData> = {};
      
      for (const trade of trades.reverse()) {
        const price = trade.price;
        if (!priceVolumes[price]) {
          priceVolumes[price] = {
            buy_volume: 0,
            sell_volume: 0,
            after_hour_buy: 0,
            after_hour_sell: 0,
            after_hour_unknown: 0,
            buy_value: 0,
            sell_value: 0,
            after_hour_buy_value: 0,
            after_hour_sell_value: 0,
            after_hour_unknown_value: 0,
            total_volume: 0,
            total_value: 0,
            volume_imbalance: 0,
            value_imbalance: 0,
            total_trades: 0
          };
        }
        
        const data = priceVolumes[price];
        const value = trade.price * trade.volume;
        
        if (trade.side === "bu") {
          data.buy_volume += trade.volume;
          data.buy_value += value;
        } else if (trade.side === "sd") {
          data.sell_volume += trade.volume;
          data.sell_value += value;
        } else {
          if (trade.price >= orderBook.ask_1.price) {
            data.after_hour_buy += trade.volume;
            data.after_hour_buy_value += value;
          } else if (trade.price <= orderBook.bid_1.price) {
            data.after_hour_sell += trade.volume;
            data.after_hour_sell_value += value;
          } else {
            data.after_hour_unknown += trade.volume;
            data.after_hour_unknown_value += value;
          }
        }
        
        data.total_trades += 1;
        data.last_trade_time = new Date(trade.time * 1000).toISOString();
      }
      
      // Calculate totals and imbalances
      for (const data of Object.values(priceVolumes)) {
        data.total_volume = 
          data.buy_volume + 
          data.sell_volume + 
          data.after_hour_buy +
          data.after_hour_sell +
          data.after_hour_unknown;
          
        data.total_value = 
          data.buy_value + 
          data.sell_value + 
          data.after_hour_buy_value +
          data.after_hour_sell_value +
          data.after_hour_unknown_value;
          
        data.volume_imbalance = 
          (data.buy_volume + data.after_hour_buy) - 
          (data.sell_volume + data.after_hour_sell);
          
        data.value_imbalance = 
          (data.buy_value + data.after_hour_buy_value) - 
          (data.sell_value + data.after_hour_sell_value);
      }
      
      return priceVolumes;
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'analyze' but doesn't specify whether this is a read-only operation, requires authentication, has rate limits, or what the output format might be. The description is vague about behavioral traits, failing to compensate for the lack of annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, though it could be slightly more structured by separating key points. Every sentence earns its place, but there's room for minor improvement in clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of stock analysis, lack of annotations, and no output schema, the description is incomplete. It doesn't explain what 'volume and value analysis' entails, the return values, or any behavioral constraints. The description fails to provide sufficient context for an agent to understand the tool's full scope and usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with clear descriptions for both parameters ('days' and 'symbol') in the input schema. The description adds no additional meaning beyond what the schema provides, such as explaining how 'volume and value analysis' relates to these parameters. Baseline score of 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as analyzing stock data with specific mention of 'volume and value analysis', providing a verb ('analyze') and resource ('stock data'). However, it doesn't explicitly differentiate from sibling tools like 'fetch-order-book' or 'fetch-trades', which might also involve stock data analysis but with different focuses or methods.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus the sibling tools ('fetch-order-book' and 'fetch-trades'), nor does it mention any prerequisites, exclusions, or alternative contexts. It lacks explicit usage instructions, leaving the agent to infer based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/Cognitive-Stack/volume-wall-detector-mcp'

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