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:
@@ -1,50 +1,38 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
|
||||
export async function GET() {
|
||||
export async function POST(request) {
|
||||
try {
|
||||
// Test calculation
|
||||
const tradingAmount = 100
|
||||
const price = 100.3703837088441
|
||||
const dbAmount = 2.04
|
||||
const leverage = 1
|
||||
|
||||
const intendedTokenAmount = tradingAmount / price
|
||||
const actualDatabaseAmount = dbAmount
|
||||
const actualPositionValue = actualDatabaseAmount * price
|
||||
const displayPositionSize = (tradingAmount * leverage).toFixed(2)
|
||||
|
||||
const testTrade = {
|
||||
side: 'BUY',
|
||||
amount: intendedTokenAmount, // Corrected amount
|
||||
tradingAmount: tradingAmount,
|
||||
leverage: leverage,
|
||||
positionSize: displayPositionSize, // Corrected position size
|
||||
price: price,
|
||||
displayInfo: {
|
||||
investedAmount: `$${tradingAmount}`,
|
||||
tokensAcquired: intendedTokenAmount.toFixed(4),
|
||||
entryPrice: `$${price.toFixed(2)}`,
|
||||
totalPositionValue: `$${displayPositionSize}`,
|
||||
leverageUsed: `${leverage}x`,
|
||||
explanation: `Invested $${tradingAmount} @ $${price.toFixed(2)}/token = ${intendedTokenAmount.toFixed(4)} tokens`,
|
||||
databaseNote: `DB stores ${actualDatabaseAmount.toFixed(2)} tokens ($${actualPositionValue.toFixed(2)} value) - display corrected to show intended $${tradingAmount} investment`
|
||||
}
|
||||
const body = await request.json()
|
||||
|
||||
// Simple trade calculation for testing
|
||||
const { amount, leverage = 1, price = 100 } = body
|
||||
|
||||
const calculation = {
|
||||
amount: parseFloat(amount) || 0,
|
||||
leverage: parseInt(leverage) || 1,
|
||||
price: parseFloat(price) || 100,
|
||||
positionSize: (parseFloat(amount) || 0) * (parseInt(leverage) || 1),
|
||||
marginRequired: (parseFloat(amount) || 0),
|
||||
timestamp: new Date().toISOString()
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: 'Trade calculation test',
|
||||
originalDatabaseValues: {
|
||||
dbAmount: dbAmount,
|
||||
dbPositionValue: actualPositionValue.toFixed(2)
|
||||
},
|
||||
correctedDisplayValues: testTrade
|
||||
calculation
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: error.message
|
||||
}, { status: 500 })
|
||||
console.error('Trade calculation error:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to calculate trade' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({
|
||||
message: 'Trade calculation endpoint',
|
||||
methods: ['POST'],
|
||||
parameters: ['amount', 'leverage', 'price']
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user