feat: fix Safe Paper Trading display formatting and API sync
- Fixed field mapping between API and frontend (amount→positionSize, entry→entryPrice, createdAt→timestamp) - Updated API sync function to properly convert API trade format to frontend format - Resolved display issues: 'Invalid Date', missing entry price, missing trade size - Added trade monitoring system and automation improvements - Enhanced automation with simple-automation.js for reliable 24/7 operation - Working automation now detecting 85% confidence BUY signals and executing trades
This commit is contained in:
@@ -4,6 +4,11 @@ import { NextResponse } from 'next/server'
|
||||
let paperTrades = []
|
||||
let tradeIdCounter = 1
|
||||
|
||||
// Export function to get trades (for other API routes)
|
||||
export function getAllPaperTrades() {
|
||||
return paperTrades
|
||||
}
|
||||
|
||||
export async function POST(request) {
|
||||
try {
|
||||
const tradeData = await request.json()
|
||||
|
||||
34
app/api/safe-paper-trading/trades/route.js
Normal file
34
app/api/safe-paper-trading/trades/route.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { getAllPaperTrades } from '../create-trade/route.js'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const trades = getAllPaperTrades()
|
||||
|
||||
// Calculate stats
|
||||
const totalTrades = trades.length
|
||||
const totalValue = trades.reduce((sum, trade) => {
|
||||
return sum + (trade.side === 'BUY' ? -trade.amount : trade.amount) + trade.pnl
|
||||
}, 0)
|
||||
|
||||
const buyTrades = trades.filter(t => t.side === 'BUY').length
|
||||
const sellTrades = trades.filter(t => t.side === 'SELL').length
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
trades: trades,
|
||||
totalTrades,
|
||||
totalValue,
|
||||
buyTrades,
|
||||
sellTrades,
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error fetching paper trades:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: 'Failed to fetch paper trades',
|
||||
error: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user