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:
43
lib/paper-trades-storage.js
Normal file
43
lib/paper-trades-storage.js
Normal file
@@ -0,0 +1,43 @@
|
||||
// Shared storage for paper trades
|
||||
// In production, this should be replaced with a proper database
|
||||
|
||||
let paperTrades = []
|
||||
let tradeIdCounter = 1
|
||||
|
||||
export function addTrade(trade) {
|
||||
const newTrade = {
|
||||
...trade,
|
||||
id: `PAPER_${Date.now()}_${tradeIdCounter++}`,
|
||||
status: 'OPEN',
|
||||
createdAt: new Date().toISOString(),
|
||||
pnl: 0,
|
||||
fees: 0
|
||||
}
|
||||
|
||||
paperTrades.push(newTrade)
|
||||
console.log(`📄 Paper trade stored: ${newTrade.id} - ${newTrade.side} ${newTrade.symbol} at $${newTrade.entry}`)
|
||||
|
||||
return newTrade
|
||||
}
|
||||
|
||||
export function getAllTrades() {
|
||||
return paperTrades
|
||||
}
|
||||
|
||||
export function getTradeStats() {
|
||||
const totalTrades = paperTrades.length
|
||||
const totalValue = paperTrades.reduce((sum, trade) => {
|
||||
return sum + (trade.side === 'BUY' ? -trade.amount : trade.amount) + trade.pnl
|
||||
}, 0)
|
||||
|
||||
const buyTrades = paperTrades.filter(t => t.side === 'BUY').length
|
||||
const sellTrades = paperTrades.filter(t => t.side === 'SELL').length
|
||||
|
||||
return {
|
||||
totalTrades,
|
||||
totalValue,
|
||||
buyTrades,
|
||||
sellTrades,
|
||||
paperTrades
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user