diff --git a/components/TradeExecutionPanel.js b/components/TradeExecutionPanel.js
index 25a1867..0978f40 100644
--- a/components/TradeExecutionPanel.js
+++ b/components/TradeExecutionPanel.js
@@ -10,24 +10,32 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) {
const [executionResult, setExecutionResult] = useState(null)
const [balance, setBalance] = useState(null)
- // Trading mode and pair selection
+ // Trading mode and coin selection
const [tradingMode, setTradingMode] = useState('SPOT') // 'SPOT' or 'PERP'
- const [tradingPair, setTradingPair] = useState('SOL/USDC') // SOL/USDC or USDC/SOL
+ const [fromCoin, setFromCoin] = useState('SOL')
+ const [toCoin, setToCoin] = useState('USDC')
+ const [perpCoin, setPerpCoin] = useState('SOL') // For perpetuals
// TP/SL functionality
const [enableStopLoss, setEnableStopLoss] = useState(false)
const [stopLoss, setStopLoss] = useState('')
const [enableTakeProfit, setEnableTakeProfit] = useState(false)
const [takeProfit, setTakeProfit] = useState('')
- const [useRealDEX, setUseRealDEX] = useState(false)
// Perp trading settings
const [leverage, setLeverage] = useState(1)
const [perpSize, setPerpSize] = useState('')
- // USDC stablecoin features
- const [quickSwapMode, setQuickSwapMode] = useState(false)
- const [usdcSwapAmount, setUsdcSwapAmount] = useState('')
+ // Available coins for trading
+ const availableCoins = [
+ { symbol: 'SOL', name: 'Solana', icon: '🟣' },
+ { symbol: 'USDC', name: 'USD Coin', icon: '💵' },
+ { symbol: 'USDT', name: 'Tether', icon: '💶' },
+ { symbol: 'BTC', name: 'Bitcoin', icon: '₿' },
+ { symbol: 'ETH', name: 'Ethereum', icon: '🔷' },
+ { symbol: 'RAY', name: 'Raydium', icon: '⚡' },
+ { symbol: 'ORCA', name: 'Orca', icon: '🐋' }
+ ]
// Auto-fill TP/SL from AI analysis
useEffect(() => {
@@ -76,62 +84,6 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) {
}
}
- const executeQuickUSDCSwap = async () => {
- if (!usdcSwapAmount || parseFloat(usdcSwapAmount) <= 0) {
- alert('Please enter a valid USDC swap amount')
- return
- }
-
- setIsExecuting(true)
- setExecutionResult(null)
-
- try {
- const swapData = {
- symbol: 'SOL',
- side: 'SELL', // Sell SOL for USDC
- amount: parseFloat(usdcSwapAmount),
- tradingPair: 'SOL/USDC',
- tradingMode: 'SPOT',
- useRealDEX: true,
- quickSwap: true
- }
-
- const response = await fetch('/api/trading/execute-dex', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(swapData)
- })
-
- const result = await response.json()
-
- if (result.success) {
- setExecutionResult({
- success: true,
- trade: result.trade,
- message: `✅ Quick swapped ${usdcSwapAmount} SOL to USDC`
- })
- await fetchBalance()
- setUsdcSwapAmount('')
- } else {
- setExecutionResult({
- success: false,
- error: result.error,
- message: result.message
- })
- }
- } catch (error) {
- setExecutionResult({
- success: false,
- error: 'Network error',
- message: 'Failed to execute USDC swap. Please try again.'
- })
- } finally {
- setIsExecuting(false)
- }
- }
-
const executeTrade = async () => {
if (!amount || parseFloat(amount) <= 0) {
alert('Please enter a valid amount')
@@ -148,14 +100,16 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) {
// Prepare trade data based on trading mode
let tradeData = {
- symbol,
+ symbol: tradingMode === 'PERP' ? perpCoin : fromCoin,
side: tradeType,
amount: parseFloat(amount),
price: tradePrice,
orderType: tradePrice ? 'limit' : 'market',
- useRealDEX: useRealDEX,
+ useRealDEX: true, // Always use real DEX
tradingMode: tradingMode,
- tradingPair: tradingPair
+ tradingPair: tradingMode === 'PERP' ? `${perpCoin}-PERP` : `${fromCoin}/${toCoin}`,
+ fromCoin: fromCoin,
+ toCoin: toCoin
}
// Add TP/SL if enabled
@@ -170,15 +124,14 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) {
if (tradingMode === 'PERP') {
tradeData.leverage = leverage
tradeData.perpSize = perpSize ? parseFloat(perpSize) : parseFloat(amount)
+ tradeData.perpCoin = perpCoin
}
// Determine API endpoint based on trading mode
- let apiEndpoint = '/api/trading/execute'
+ let apiEndpoint = '/api/trading/execute-dex'
if (tradingMode === 'PERP') {
apiEndpoint = '/api/trading/execute-perp'
- } else if (useRealDEX || quickSwapMode) {
- apiEndpoint = '/api/trading/execute-dex'
}
const response = await fetch(apiEndpoint, {
@@ -319,59 +272,107 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) {
- {/* Trading Pair Selection (for Spot) */}
+ {/* Coin Selection for Spot Trading */}
{tradingMode === 'SPOT' && (
-
Trading Pair
-
-
setTradingPair('SOL/USDC')}
- className={`py-2 px-3 rounded-lg font-medium transition-colors text-sm ${
- tradingPair === 'SOL/USDC'
- ? 'bg-purple-600 text-white'
- : 'bg-gray-700 text-gray-300 hover:bg-gray-600'
- }`}
- >
- SOL → USDC
-
-
setTradingPair('USDC/SOL')}
- className={`py-2 px-3 rounded-lg font-medium transition-colors text-sm ${
- tradingPair === 'USDC/SOL'
- ? 'bg-green-600 text-white'
- : 'bg-gray-700 text-gray-300 hover:bg-gray-600'
- }`}
- >
- USDC → SOL
-
+
Swap Coins
+
+ {/* From Coin */}
+
+ From
+ setFromCoin(e.target.value)}
+ className="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
+ >
+ {availableCoins.map(coin => (
+
+ {coin.icon} {coin.symbol}
+
+ ))}
+
+
+
+ {/* Swap Arrow */}
+
+ {
+ const temp = fromCoin
+ setFromCoin(toCoin)
+ setToCoin(temp)
+ }}
+ className="p-2 bg-gray-600 hover:bg-gray-500 rounded-lg transition-colors"
+ title="Swap coins"
+ >
+ 🔄
+
+
+
+ {/* To Coin */}
+
+ To
+ setToCoin(e.target.value)}
+ className="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
+ >
+ {availableCoins.map(coin => (
+
+ {coin.icon} {coin.symbol}
+
+ ))}
+
+
-
- {tradingPair === 'SOL/USDC' ? 'Swap SOL for USDC stablecoin' : 'Buy SOL with USDC'}
+
+ Swap {fromCoin} → {toCoin} via Jupiter DEX
)}
- {/* Leverage Selection (for Perps) */}
+ {/* Coin Selection and Leverage for Perpetuals */}
{tradingMode === 'PERP' && (
-
-
Leverage
-
- {[1, 2, 5, 10].map(lev => (
-
setLeverage(lev)}
- className={`py-2 px-3 rounded-lg font-medium transition-colors text-sm ${
- leverage === lev
- ? 'bg-orange-600 text-white'
- : 'bg-gray-700 text-gray-300 hover:bg-gray-600'
- }`}
- >
- {lev}x
-
- ))}
+
+ {/* Perpetual Coin Selection */}
+
+
Perpetual Asset
+
setPerpCoin(e.target.value)}
+ className="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-orange-500"
+ >
+ {availableCoins.filter(coin => coin.symbol !== 'USDC' && coin.symbol !== 'USDT').map(coin => (
+
+ {coin.icon} {coin.symbol} Perpetual
+
+ ))}
+
+
+ Choose the asset you want to trade with leverage
+
-
- ⚠️ Higher leverage = Higher risk. Max 10x for safety.
+
+ {/* Leverage Selection */}
+
+
Leverage
+
+ {[1, 2, 5, 10].map(lev => (
+ setLeverage(lev)}
+ className={`py-2 px-3 rounded-lg font-medium transition-colors text-sm ${
+ leverage === lev
+ ? 'bg-orange-600 text-white'
+ : 'bg-gray-700 text-gray-300 hover:bg-gray-600'
+ }`}
+ >
+ {lev}x
+
+ ))}
+
+
+ ⚠️ Higher leverage = Higher risk. Max 10x for safety.
+
)}
@@ -403,7 +404,10 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) {
{/* Amount Input */}
{/* Price Selection */}
@@ -522,116 +532,13 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) {
- {/* DEX Selection */}
-
-
Execution Method
-
-
- setUseRealDEX(false)}
- className={`py-2 px-3 rounded-lg font-medium transition-colors text-sm ${
- !useRealDEX
- ? 'bg-blue-600 text-white'
- : 'bg-gray-700 text-gray-300 hover:bg-gray-600'
- }`}
- >
- 📊 Simulation
-
- setUseRealDEX(true)}
- className={`py-2 px-3 rounded-lg font-medium transition-colors text-sm ${
- useRealDEX
- ? 'bg-purple-600 text-white'
- : 'bg-gray-700 text-gray-300 hover:bg-gray-600'
- }`}
- >
- 🚀 Jupiter DEX
-
-
-
-
- {useRealDEX
- ? '⚠️ Real DEX trading uses your actual SOL/USDC and costs gas fees'
- : '🎮 Simulation mode for testing strategies without real trades'
- }
-
-
-
- {/* Quick USDC Swap - Spot mode only */}
- {tradingMode === 'SPOT' && (
-
-
- 💱 Quick USDC Swap
- STABLE
-
-
-
- Instantly convert SOL to USDC stablecoin to lock in profits or avoid volatility
-
-
-
- setUsdcSwapAmount(e.target.value)}
- placeholder="SOL amount"
- step="0.01"
- min="0"
- className="flex-1 px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500"
- />
-
- {isExecuting ? '⏳' : '💱 Swap'}
-
-
-
-
- Real-time swap via Jupiter DEX • Low slippage • Instant execution
-
-
- )}
-
- {/* Jupiter Perpetuals Integration - Perp mode only */}
- {tradingMode === 'PERP' && (
-
-
- ⚡ Jupiter Perpetuals
- LEVERAGE
-
-
-
- Trade with leverage on Jupiter's perpetual DEX • Long or Short any asset
-
-
-
-
-
Leverage:
-
{leverage}x
-
-
-
Liquidation Risk:
-
- {leverage <= 2 ? 'Low' : leverage <= 5 ? 'Medium' : 'High'}
-
-
-
-
-
- 🚧 Jupiter Perpetuals integration in development. Currently using simulation mode.
-
-
- )}
-
{/* Execute Button */}
- {isExecuting ? 'Executing...' : `${useRealDEX ? '🚀 Execute' : '🎮 Simulate'} ${tradeType} Order${(enableStopLoss || enableTakeProfit) ? ' + TP/SL' : ''}`}
+ {isExecuting ? 'Executing...' : `🚀 Execute ${tradeType} ${tradingMode === 'PERP' ? `${perpCoin} ${leverage}x` : `${fromCoin}→${toCoin}`}${(enableStopLoss || enableTakeProfit) ? ' + TP/SL' : ''}`}
{/* Execution Result */}
@@ -655,7 +562,7 @@ export default function TradeExecutionPanel({ analysis, symbol = 'SOL' }) {
{/* Risk Warning */}
- ⚠️ Trading involves significant risk. This is a simulated trading environment using Bitquery data.
+ ⚠️ Trading involves significant risk of loss. Real trades executed via Jupiter DEX using your actual wallet funds.
)