Implement pure Drift Protocol automation system
- Remove Jupiter DEX completely from automation system - Implement exclusive Drift Protocol integration with up to 100x leverage - Update executeLiveTrade method to use only Drift API endpoints - Change default DEX provider from Jupiter to Drift - Create minimal professional UI without promotional banners - Add comprehensive leverage options (1x-100x) with risk indicators - Update automation service to route all trades through /api/automation/trade - Fix type definitions to support Drift-only configuration - Add multiple trading pairs support (SOL, BTC, ETH, APT, AVAX, DOGE) - Implement clean configuration interface with essential controls - Remove excessive marketing text and promotional elements - Maintain full automation functionality while simplifying UX
This commit is contained in:
@@ -805,7 +805,7 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r.
|
||||
if (tradeResult.status !== 'FAILED') {
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
await aggressiveCleanup.forceCleanupAfterTrade()
|
||||
await aggressiveCleanup.runPostAnalysisCleanup()
|
||||
} catch (error) {
|
||||
console.error('Error in post-trade cleanup:', error)
|
||||
}
|
||||
@@ -852,52 +852,53 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r.
|
||||
}
|
||||
|
||||
private async executeLiveTrade(decision: any): Promise<any> {
|
||||
// Execute real trade via Jupiter DEX
|
||||
const inputToken = decision.direction === 'BUY' ? 'USDC' : 'SOL'
|
||||
const outputToken = decision.direction === 'BUY' ? 'SOL' : 'USDC'
|
||||
|
||||
const tokens = {
|
||||
SOL: 'So11111111111111111111111111111111111111112',
|
||||
USDC: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
||||
}
|
||||
try {
|
||||
console.log(`🚀 Executing DRIFT trade: ${decision.direction} ${decision.positionSize} ${this.config!.symbol} with ${this.config!.maxLeverage}x leverage`)
|
||||
|
||||
const response = await fetch("http://localhost:3000/api/automation/trade", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
dexProvider: "DRIFT",
|
||||
action: decision.direction.toLowerCase() === "buy" ? "open_long" : "open_short",
|
||||
symbol: this.config!.symbol.replace("USD", ""), // Convert SOLUSD to SOL
|
||||
amount: this.config!.tradingAmount,
|
||||
side: decision.direction,
|
||||
leverage: this.config!.maxLeverage,
|
||||
stopLoss: decision.stopLoss,
|
||||
takeProfit: decision.takeProfit,
|
||||
mode: "LIVE"
|
||||
})
|
||||
})
|
||||
|
||||
// Calculate proper amount for Jupiter API
|
||||
let swapAmount
|
||||
if (decision.direction === 'BUY') {
|
||||
// BUY: Use trading amount in USDC (convert to 6 decimals)
|
||||
swapAmount = Math.floor(this.config!.tradingAmount * 1e6) // USDC has 6 decimals
|
||||
console.log(`💱 BUY: Converting $${this.config!.tradingAmount} USDC to ${swapAmount} USDC tokens`)
|
||||
} else {
|
||||
// SELL: Use SOL amount (convert to 9 decimals)
|
||||
swapAmount = Math.floor(decision.positionSize * 1e9) // SOL has 9 decimals
|
||||
console.log(`💱 SELL: Converting ${decision.positionSize} SOL to ${swapAmount} SOL tokens`)
|
||||
}
|
||||
|
||||
console.log(`🔄 Executing Jupiter swap with corrected amount: ${swapAmount}`)
|
||||
|
||||
const swapResult = await jupiterDEXService.executeSwap(
|
||||
tokens[inputToken as keyof typeof tokens],
|
||||
tokens[outputToken as keyof typeof tokens],
|
||||
swapAmount,
|
||||
50 // 0.5% slippage
|
||||
)
|
||||
|
||||
// Convert Jupiter result to standard trade result format
|
||||
if (swapResult.success) {
|
||||
return {
|
||||
transactionId: swapResult.txId,
|
||||
executionPrice: swapResult.executionPrice,
|
||||
amount: swapResult.outputAmount, // Amount of tokens received
|
||||
direction: decision.direction,
|
||||
status: 'COMPLETED',
|
||||
timestamp: new Date(),
|
||||
fees: swapResult.fees || 0,
|
||||
slippage: swapResult.slippage || 0,
|
||||
inputAmount: swapResult.inputAmount, // Amount of tokens spent
|
||||
tradingAmount: this.config!.tradingAmount // Original USD amount
|
||||
if (!response.ok) {
|
||||
throw new Error(`Drift trade request failed: ${response.statusText}`)
|
||||
}
|
||||
} else {
|
||||
throw new Error(swapResult.error || 'Jupiter swap failed')
|
||||
|
||||
const result = await response.json()
|
||||
|
||||
if (result.success) {
|
||||
return {
|
||||
transactionId: result.result?.transactionId || result.txId,
|
||||
executionPrice: result.result?.executionPrice || decision.currentPrice,
|
||||
amount: result.result?.amount || decision.positionSize,
|
||||
direction: decision.direction,
|
||||
status: "COMPLETED",
|
||||
timestamp: new Date(),
|
||||
fees: result.result?.fees || 0,
|
||||
slippage: result.result?.slippage || 0,
|
||||
leverage: this.config!.maxLeverage,
|
||||
dexProvider: "DRIFT",
|
||||
tradingAmount: this.config!.tradingAmount
|
||||
}
|
||||
} else {
|
||||
throw new Error(result.error || "Drift trade execution failed")
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Live trade execution error:", error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user