// Supported exchanges const EXCHANGES = { CEX: ['Binance', 'Coinbase', 'Kraken', 'KuCoin', 'OKX', 'Bybit', 'Bitget', 'Huobi', 'Gate.io'], DEX: ['Uniswap', 'PancakeSwap', 'SushiSwap', 'Curve', 'Balancer', 'Jupiter', 'QuickSwap', 'Trader Joe'] }; // Fetch top 200 coins from CoinGecko async function fetchTopCoins() { try { const response = await fetch('https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=200&page=1&sparkline=false'); const data = await response.json(); return data.map(coin => coin.symbol.toUpperCase()); } catch (error) { console.error('Error fetching top coins:', error); return ['BTC', 'ETH', 'BNB', 'SOL', 'ADA', 'XRP', 'DOT', 'DOGE', 'SHIB', 'MATIC']; } } // Fetch prices from Binance API async function fetchBinancePrices(symbols) { try { const response = await fetch('https://api.binance.com/api/v3/ticker/price'); const data = await response.json(); return data.filter(item => symbols.includes(item.symbol.replace('USDT', ''))); } catch (error) { console.error('Error fetching Binance prices:', error); return []; } } // Simulate DEX prices with slight variation from CEX prices function simulateDexPrices(cexPrices) { return cexPrices.map(item => { const variation = (Math.random() * 0.05) - 0.025; // -2.5% to +2.5% const price = parseFloat(item.price) * (1 + variation); return { symbol: item.symbol.replace('USDT', ''), price: price.toFixed(8) }; }); } // Find arbitrage opportunities async function findArbitrageOpportunities() { const symbols = await fetchTopCoins(); const binancePrices = await fetchBinancePrices(symbols); const dexPrices = simulateDexPrices(binancePrices); const opportunities = []; // Compare Binance (CEX) with simulated DEX prices binancePrices.forEach(cexItem => { const symbol = cexItem.symbol.replace('USDT', ''); const dexItem = dexPrices.find(item => item.symbol === symbol); if (dexItem) { const cexPrice = parseFloat(cexItem.price); const dexPrice = parseFloat(dexItem.price); const spread = ((dexPrice - cexPrice) / cexPrice) * 100; if (Math.abs(spread) > 0.5) { // Only show opportunities with >0.5% spread opportunities.push({ symbol, buyFrom: spread > 0 ? 'Binance' : EXCHANGES.DEX[Math.floor(Math.random() * EXCHANGES.DEX.length)], sellTo: spread > 0 ? EXCHANGES.DEX[Math.floor(Math.random() * EXCHANGES.DEX.length)] : 'Binance', buyPrice: spread > 0 ? cexPrice : dexPrice, sellPrice: spread > 0 ? dexPrice : cexPrice, profitPercent: Math.abs(spread), liquidity: Math.floor(Math.random() * 10000000) + 100000, confidence: Math.floor(Math.random() * 30) + 70, status: spread > 10 ? 'EXTREME_ARBITRAGE' : 'GOOD_ARBITRAGE' }); } } }); return { active: opportunities.filter(opp => opp.profitPercent <= 10), extreme: opportunities.filter(opp => opp.profitPercent > 10), expired: [], inactive: [], coins: symbols.map(symbol => { const cexItem = binancePrices.find(item => item.symbol === `${symbol}USDT`); const dexItem = dexPrices.find(item => item.symbol === symbol); return { symbol, cexPrice: cexItem ? parseFloat(cexItem.price) : 0, dexPrice: dexItem ? parseFloat(dexItem.price) : 0, spread: cexItem && dexItem ? ((parseFloat(dexItem.price) - parseFloat(cexItem.price)) / parseFloat(cexItem.price)) * 100 : 0 }; }) }; } // Render arbitrage opportunities async function renderArbitrage() { const data = await findArbitrageOpportunities(); const activeContainer = document.getElementById('active-arbitrage'); const extremeContainer = document.getElementById('extreme-arbitrage'); const expiredContainer = document.getElementById('expired-arbitrage'); const inactiveContainer = document.getElementById('inactive-arbitrage'); const coinList = document.getElementById('coin-list'); // Clear existing content activeContainer.innerHTML = ''; extremeContainer.innerHTML = ''; expiredContainer.innerHTML = ''; inactiveContainer.innerHTML = ''; coinList.innerHTML = ''; // Render active arbitrage mockData.active.forEach(opp => { const card = document.createElement('arbitrage-card'); card.setAttribute('data', JSON.stringify(opp)); activeContainer.appendChild(card); }); // Render extreme arbitrage mockData.extreme.forEach(opp => { const card = document.createElement('arbitrage-card'); card.setAttribute('data', JSON.stringify(opp)); extremeContainer.appendChild(card); }); // Render expired arbitrage mockData.expired.forEach(opp => { const card = document.createElement('arbitrage-card'); card.setAttribute('data', JSON.stringify(opp)); expiredContainer.appendChild(card); }); // Render inactive arbitrage mockData.inactive.forEach(opp => { const card = document.createElement('arbitrage-card'); card.setAttribute('data', JSON.stringify(opp)); inactiveContainer.appendChild(card); }); // Render coin list mockData.coins.forEach(coin => { const row = document.createElement('tr'); row.className = 'border-b border-gray-700 hover:bg-gray-700/50'; row.innerHTML = `