Skip to main content
Glama

check_arbitrage_opportunities

Identify arbitrage opportunities by comparing price differences between centralized exchanges and SailFish DEX. Set a custom threshold to filter results based on minimum percentage gain.

Instructions

Check for arbitrage opportunities between centralized exchanges and SailFish DEX

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
thresholdNoMinimum price difference percentage to consider as an arbitrage opportunity (default: 1.0)

Implementation Reference

  • The core handler function that fetches CEX price from CryptoCompare API and DEX price from SailFish subgraph, calculates price difference, determines if there's an arbitrage opportunity above the threshold, and returns detailed results including direction and potential profit.
    export async function checkArbitrageOpportunities(threshold: number = 1.0): Promise<{
      cexPrice: number;
      dexPrice: number;
      priceDifference: number;
      priceDifferencePercentage: number;
      arbitrageOpportunity: boolean;
      direction: 'BUY_CEX_SELL_DEX' | 'BUY_DEX_SELL_CEX' | 'NONE';
      potentialProfit: number;
      timestamp: string;
    }> {
      try {
        // Get external market data
        const externalData = await getExternalMarketData();
        const cexPrice = externalData.price;
        
        // Get DEX price from SailFish
        const dexPrice = await subgraph.getEthPrice();
        const dexPriceNumber = parseFloat(dexPrice || '0');
        
        // Calculate price difference
        const priceDifference = Math.abs(cexPrice - dexPriceNumber);
        const priceDifferencePercentage = (priceDifference / Math.min(cexPrice, dexPriceNumber)) * 100;
        
        // Determine arbitrage opportunity
        const arbitrageOpportunity = priceDifferencePercentage >= threshold;
        
        // Determine direction
        let direction: 'BUY_CEX_SELL_DEX' | 'BUY_DEX_SELL_CEX' | 'NONE' = 'NONE';
        if (arbitrageOpportunity) {
          direction = cexPrice < dexPriceNumber ? 'BUY_CEX_SELL_DEX' : 'BUY_DEX_SELL_CEX';
        }
        
        // Calculate potential profit (simplified)
        const potentialProfit = arbitrageOpportunity ? priceDifference : 0;
        
        return {
          cexPrice,
          dexPrice: dexPriceNumber,
          priceDifference,
          priceDifferencePercentage,
          arbitrageOpportunity,
          direction,
          potentialProfit,
          timestamp: new Date().toISOString()
        };
      } catch (error) {
        console.error('Error checking arbitrage opportunities:', error);
        throw error;
      }
    }
  • Defines the tool name, description, and input schema for check_arbitrage_opportunities, specifying an optional threshold parameter.
      name: 'check_arbitrage_opportunities',
      description: 'Check for arbitrage opportunities between centralized exchanges and SailFish DEX',
      inputSchema: {
        type: 'object',
        properties: {
          threshold: {
            type: 'number',
            description: 'Minimum price difference percentage to consider as an arbitrage opportunity (default: 1.0)',
          },
        },
        required: [],
      },
    },
  • src/index.ts:1285-1314 (registration)
    Registers the tool handler in the MCP CallToolRequestSchema switch statement, validates input, calls the external_market.checkArbitrageOpportunities function, and formats the MCP response.
    case 'check_arbitrage_opportunities': {
      try {
        const threshold = typeof args.threshold === 'number' ? args.threshold : 1.0;
        const opportunities = await external_market.checkArbitrageOpportunities(threshold);
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(opportunities, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error('Error checking arbitrage opportunities:', error);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({ 
                error: 'Failed to check arbitrage opportunities',
                message: (error as Error).message,
                note: 'You may need to update the external market API configuration'
              }, null, 2),
            },
          ],
          isError: true,
        };
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but only states the purpose without detailing traits like rate limits, authentication needs, computational cost, or what constitutes an 'opportunity' (e.g., format, confidence). This leaves significant gaps for a tool that likely involves complex data analysis.

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

Conciseness5/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 any fluff or redundancy. It is appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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 tool's complexity (involving arbitrage across exchanges and DEX), lack of annotations, and no output schema, the description is insufficient. It doesn't explain what the output entails (e.g., list of opportunities, calculations), behavioral constraints, or error handling, leaving the agent under-informed for effective use.

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 input schema has 100% description coverage for its single parameter (threshold), clearly explaining it as a minimum price difference percentage with a default. The description adds no additional parameter semantics beyond what the schema provides, so it meets the baseline for high schema coverage.

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 action ('Check for arbitrage opportunities') and specifies the resources involved ('between centralized exchanges and SailFish DEX'), which distinguishes it from most sibling tools that focus on data retrieval or transactions. However, it doesn't explicitly differentiate from potential arbitrage-related siblings (none are listed), keeping it from a perfect score.

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 alternatives, such as other arbitrage tools (none in siblings) or related tools like get_token_price or get_swap_quote. It lacks context on prerequisites, timing, or exclusions, leaving the agent with minimal usage direction.

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/SailFish-Finance/educhain-ai-agent-kit'

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