"use client" import React, { useState } from 'react' interface TradeParams { symbol: string side: 'LONG' | 'SHORT' amount: number leverage: number orderType?: 'MARKET' | 'LIMIT' price?: number stopLoss?: number takeProfit?: number stopLossType?: string takeProfitType?: string } export default function DriftTradingPanel() { const [symbol, setSymbol] = useState('SOL-PERP') const [side, setSide] = useState<'LONG' | 'SHORT'>('LONG') const [amount, setAmount] = useState('') const [leverage, setLeverage] = useState(1) const [orderType, setOrderType] = useState<'MARKET' | 'LIMIT'>('MARKET') const [price, setPrice] = useState('') const [stopLoss, setStopLoss] = useState('') const [takeProfit, setTakeProfit] = useState('') const [loading, setLoading] = useState(false) const [result, setResult] = useState(null) const availableSymbols = [ 'SOL-PERP', 'BTC-PERP', 'ETH-PERP', 'DOT-PERP', 'AVAX-PERP', 'ADA-PERP', 'MATIC-PERP', 'LINK-PERP', 'ATOM-PERP', 'NEAR-PERP', 'APT-PERP', 'ORBS-PERP', 'RND-PERP', 'WIF-PERP', 'JUP-PERP', 'TNS-PERP', 'DOGE-PERP', 'PEPE-PERP', 'POPCAT-PERP', 'BOME-PERP' ] const handleTrade = async () => { if (!amount || parseFloat(amount) <= 0) { setResult({ success: false, error: 'Please enter a valid amount' }) return } if (orderType === 'LIMIT' && (!price || parseFloat(price) <= 0)) { setResult({ success: false, error: 'Please enter a valid price for limit orders' }) return } setLoading(true) setResult(null) try { const tradeParams: TradeParams = { symbol, side, amount: parseFloat(amount), leverage, orderType, price: orderType === 'LIMIT' ? parseFloat(price) : undefined, stopLoss: stopLoss ? parseFloat(stopLoss) : undefined, takeProfit: takeProfit ? parseFloat(takeProfit) : undefined, stopLossType: 'MARKET', takeProfitType: 'MARKET' } const response = await fetch('/api/drift/trade', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(tradeParams) }) const data = await response.json() setResult(data) if (data.success) { // Clear form on success setAmount('') setPrice('') } } catch (error: any) { setResult({ success: false, error: error.message }) } finally { setLoading(false) } } return (

🌊 Drift Trading

Live
{/* Symbol Selection */}
{/* Side Selection */}
{/* Order Type */}
{/* Amount */}
setAmount(e.target.value)} placeholder="100.00" min="0" step="0.01" className="input w-full" />
{/* Leverage */}
setLeverage(parseInt(e.target.value))} className="w-full h-2 bg-gray-700 rounded-lg appearance-none cursor-pointer" />
1x 5x 10x 20x
{/* Price (only for limit orders) */} {orderType === 'LIMIT' && (
setPrice(e.target.value)} placeholder="0.00" min="0" step="0.01" className="input w-full" />
)} {/* Risk Management */}
setStopLoss(e.target.value)} placeholder="Optional" min="0" step="0.01" className="input w-full" />
setTakeProfit(e.target.value)} placeholder="Optional" min="0" step="0.01" className="input w-full" />
{/* Trade Button */} {/* Result Display */} {result && (
{result.success ? (

✅ Trade Executed Successfully!

{result.txId && (

TX: {result.txId.slice(0, 8)}...{result.txId.slice(-8)}

)}
) : (

❌ {result.error}

)}
)}
) }