feat: Enhanced Jupiter DEX with full bidirectional trading support
MAJOR ENHANCEMENTS:
- Added SELL signal processing in automation service
- Smart position management with SOL holdings verification
- Risk-adjusted sell amounts based on current portfolio
- Proper swap direction logic (SOL → USDC for shorts)
- Enhanced stop loss/take profit for both BUY and SELL orders
- Fixed investment amount calculations (corrected from 00 to actual 4)
- Implemented proportional P&L adjustment for historical trades
- Synchronized price data between analysis-details and price-monitor APIs
- Enhanced active trades display with priority sorting and visual indicators
- checkCurrentPosition(): Verifies SOL holdings before SELL orders
- calculateSellAmount(): Risk-based position sizing for shorts
- Enhanced TP/SL calculations for bidirectional trading
- Real-time price synchronization across all endpoints
- Active trades monitoring with visual enhancements
- BUY: USDC → SOL (profit from price increases)
- SELL: SOL → USDC (profit from price decreases)
- Position-aware risk management
- Confidence-based position sizing
- Proper decimal handling (SOL=9, USDC=6)
- Comprehensive Jupiter shorting test suite
- P&L calculation verification
- Position management validation
- API endpoint testing
- P&L corrected from .15 to /bin/bash.78 for 4 investment
- Active trades display enhanced with blue borders and pulsing indicators
- Full bidirectional trading now available
- Risk-managed shorting based on actual holdings
This enables making money in both bull and bear markets! 🎯
This commit is contained in:
@@ -93,6 +93,11 @@ class JupiterDEXService {
|
||||
success: boolean
|
||||
txId?: string
|
||||
error?: string
|
||||
executionPrice?: number
|
||||
inputAmount?: number
|
||||
outputAmount?: number
|
||||
fees?: number
|
||||
slippage?: number
|
||||
}> {
|
||||
if (!this.keypair) {
|
||||
return { success: false, error: 'Wallet not initialized' }
|
||||
@@ -139,8 +144,30 @@ class JupiterDEXService {
|
||||
return { success: false, error: `Transaction failed: ${confirmation.value.err}` }
|
||||
}
|
||||
|
||||
// 6. Calculate execution details from quote
|
||||
const inputAmount = parseFloat(quote.inAmount)
|
||||
const outputAmount = parseFloat(quote.outAmount)
|
||||
|
||||
// Calculate execution price based on swap direction
|
||||
let executionPrice: number
|
||||
if (inputMint === this.tokens.USDC) {
|
||||
// Buying SOL with USDC: price = USDC spent / SOL received
|
||||
executionPrice = (inputAmount / 1e6) / (outputAmount / 1e9) // Convert from token units
|
||||
} else {
|
||||
// Selling SOL for USDC: price = USDC received / SOL spent
|
||||
executionPrice = (outputAmount / 1e6) / (inputAmount / 1e9) // Convert from token units
|
||||
}
|
||||
|
||||
console.log('✅ Jupiter swap successful:', txId)
|
||||
return { success: true, txId }
|
||||
return {
|
||||
success: true,
|
||||
txId,
|
||||
executionPrice,
|
||||
inputAmount: inputAmount / (inputMint === this.tokens.USDC ? 1e6 : 1e9),
|
||||
outputAmount: outputAmount / (outputMint === this.tokens.USDC ? 1e6 : 1e9),
|
||||
fees: (inputAmount / (inputMint === this.tokens.USDC ? 1e6 : 1e9)) * 0.001, // Estimate 0.1% fees
|
||||
slippage: parseFloat(quote.priceImpactPct || '0')
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('❌ Jupiter swap failed:', error)
|
||||
|
||||
Reference in New Issue
Block a user