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

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

Input Schema (JSON Schema)

{ "properties": { "threshold": { "description": "Minimum price difference percentage to consider as an arbitrage opportunity (default: 1.0)", "type": "number" } }, "required": [], "type": "object" }

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, }; } }

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