| scripts | {"price":{"description":"Get SOL price, indicators (SMA, RSI), funding rate","execute":"const connection = new Connection(process.env.SOLANA_RPC_URL, 'confirmed');\nconst driftClient = await getDriftClient(wallet, process.env.SOLANA_RPC_URL);\nconst marketIndex = await getPerpMarketIndex('SOL');\nconst data = await getMarketData(driftClient, marketIndex, 'SOL');\nreturn {\n price: data.lastPrice,\n bid: data.bid,\n ask: data.ask,\n fundingRate: `${data.fundingRate.toFixed(4)}%`,\n longPct: `${data.longPct.toFixed(1)}%`,\n shortPct: `${data.shortPct.toFixed(1)}%`,\n RSI: data.rsi.toFixed(1),\n message: `SOL: $${data.lastPrice} | Funding: ${data.fundingRate.toFixed(4)}% | Long: ${data.longPct.toFixed(1)}% | RSI: ${data.rsi.toFixed(1)}`\n};\n"},"position":{"description":"Check open perp positions, PnL, margin","execute":"const apiKey = process.env.API_KEY;\nconst apiUrl = process.env.API_URL || 'http://localhost:3001';\nconst response = await fetch(`${apiUrl}/api/trades/positions`, {\n headers: { 'Authorization': `Bearer ${apiKey}` }\n});\nconst { positions } = await response.json();\nif (positions.length === 0) {\n return { message: 'No open positions.', positions: [] };\n}\nconst totalPnl = positions.reduce((sum, p) => sum + (p.unrealizedPnl || 0), 0);\nreturn {\n positions,\n totalPnl,\n message: positions.map(p =>\n `${p.direction.toUpperCase()} ${p.market}: ${p.size} @ $${p.entryPrice.toFixed(2)} → PnL: $${(p.unrealizedPnl || 0).toFixed(2)} | Fee: $${(p.feeCharged || 0).toFixed(2)}`\n ).join('\\n')\n};\n"},"trade":{"description":"Open long or short perpetual position via API (10% fee on profit)","params":[{"name":"direction","type":"string","required":true,"enum":["long","short"],"description":"long or short"},{"name":"size","type":"number","required":true,"description":"Position size in SOL"},{"name":"leverage","type":"number","required":false,"default":3,"description":"Leverage multiplier"},{"name":"strategy","type":"string","required":false,"default":"shark","description":"Trading strategy (shark/wolf/grid)"}],"execute":"const apiKey = process.env.API_KEY;\nconst apiUrl = process.env.API_URL || 'http://localhost:3001';\nconst response = await fetch(`${apiUrl}/api/trades/execute`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${apiKey}`\n },\n body: JSON.stringify({ direction, size, leverage, strategy })\n});\nconst result = await response.json();\nif (!response.ok) throw new Error(result.error);\nreturn { \n positionId: result.positionId,\n entryPrice: result.entryPrice,\n fee: '10% performance fee on profit when closed',\n message: `${direction.toUpperCase()} ${size} SOL @ ${leverage}x. Position ID: ${result.positionId}. 10% fee charged on profit at close.`\n};\n"},"close":{"description":"Close open position via API (triggers 10% fee deduction)","params":[{"name":"market","type":"string","required":false,"default":"SOL","description":"Market to close"}],"execute":"const apiKey = process.env.API_KEY;\nconst apiUrl = process.env.API_URL || 'http://localhost:3001';\nconst positionsRes = await fetch(`${apiUrl}/api/trades/positions`, {\n headers: { 'Authorization': `Bearer ${apiKey}` }\n});\nconst { positions } = await positionsRes.json();\nif (positions.length === 0) return { message: 'No positions to close.' };\nconst positionId = positions[0].positionId;\nconst closeRes = await fetch(`${apiUrl}/api/trades/close`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${apiKey}`\n },\n body: JSON.stringify({ positionId })\n});\nconst result = await closeRes.json();\nreturn { \n ...result,\n message: `Position ${positionId} closed. Net PnL: $${result.netPnl?.toFixed(2)} | Fee collected: $${result.feeCharged?.toFixed(2)}`\n};\n"},"balance":{"description":"Check Drift collateral balance and buying power","execute":"const connection = new Connection(process.env.SOLANA_RPC_URL, 'confirmed');\nconst driftClient = await getDriftClient(wallet, process.env.SOLANA_RPC_URL);\nconst collateral = await getTotalCollateral(driftClient);\nconst solBalance = await connection.getBalance(wallet.publicKey);\nreturn {\n driftCollateral: collateral,\n solBalance: solBalance / 1e9,\n buyingPower: collateral,\n message: `Drift: $${collateral.toFixed(2)} | SOL: ${(solBalance / 1e9).toFixed(4)}`\n};\n"},"market":{"description":"Get market sentiment, funding rate, open interest","execute":"const connection = new Connection(process.env.SOLANA_RPC_URL, 'confirmed');\nconst driftClient = await getDriftClient(wallet, process.env.SOLANA_RPC_URL);\nconst marketIndex = await getPerpMarketIndex('SOL');\nconst data = await getMarketData(driftClient, marketIndex, 'SOL');\nreturn {\n fundingRate: `${data.fundingRate.toFixed(4)}%`,\n openInterest: data.openInterest.toFixed(2),\n longPct: `${data.longPct.toFixed(1)}%`,\n shortPct: `${data.shortPct.toFixed(1)}%`,\n sentiment: data.longPct > 60 ? 'BEARISH' : data.longPct < 40 ? 'BULLISH' : 'NEUTRAL',\n message: `Funding: ${data.fundingRate.toFixed(4)}% | OI: ${data.openInterest.toFixed(0)} | Long: ${data.longPct.toFixed(1)}% | Sentiment: ${data.longPct > 60 ? 'BEARISH' : data.longPct < 40 ? 'BULLISH' : 'NEUTRAL'}`\n};\n"},"portfolio":{"description":"Get full portfolio via API including positions, balances, and fee history","execute":"const apiKey = process.env.API_KEY;\nconst apiUrl = process.env.API_URL || 'http://localhost:3001';\nconst response = await fetch(`${apiUrl}/api/portfolio`, {\n headers: { 'Authorization': `Bearer ${apiKey}` }\n});\nconst portfolio = await response.json();\nreturn {\n ...portfolio,\n message: `Total: $${portfolio.totalValue.toFixed(2)} | USDC: $${portfolio.usdcBalance.toFixed(2)} | USDC+: $${portfolio.usdcPlusBalance.toFixed(2)} | Open: ${portfolio.openPositions.length} | Fees Paid: $${portfolio.totalFeesPaid.toFixed(2)}`\n};\n"}} |