"use client" import React, { useState } from 'react' interface TradeParams { symbol: string side: 'BUY' | 'SELL' amount: number orderType?: 'MARKET' | 'LIMIT' price?: number } export default function DriftTradingPanel() { const [symbol, setSymbol] = useState('SOLUSD') const [side, setSide] = useState<'BUY' | 'SELL'>('BUY') const [amount, setAmount] = useState('') const [orderType, setOrderType] = useState<'MARKET' | 'LIMIT'>('MARKET') const [price, setPrice] = useState('') const [loading, setLoading] = useState(false) const [result, setResult] = useState(null) const availableSymbols = [ 'SOLUSD', 'BTCUSD', 'ETHUSD', 'DOTUSD', 'AVAXUSD', 'ADAUSD', 'MATICUSD', 'LINKUSD', 'ATOMUSD', 'NEARUSD', 'APTUSD', 'ORBSUSD', 'RNDUSD', 'WIFUSD', 'JUPUSD', 'TNSUSD', 'DOGEUSD', 'PEPE1KUSD', 'POPCATUSD', 'BOMERUSD' ] 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), orderType, price: orderType === 'LIMIT' ? parseFloat(price) : undefined } const response = await fetch('/api/trading', { 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" />
{/* Price (only for limit orders) */} {orderType === 'LIMIT' && (
setPrice(e.target.value)} placeholder="0.00" 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}

)}
)}
) }