Add 'Clear Manual Closes' button to analytics
- New button in analytics page to clear orphaned trades - API endpoint /api/trading/clear-manual-closes - Intelligently checks Drift positions before deleting - Only removes trades with no matching position or mismatched entry price - Safe operation: keeps trades on error (false positives better than deletions) - User-friendly confirmation dialog
This commit is contained in:
@@ -100,6 +100,29 @@ export default function AnalyticsPage() {
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
const clearManuallyClosed = async () => {
|
||||
if (!confirm('Clear all open trades from database? Use this if you manually closed positions in Drift UI.')) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/trading/clear-manual-closes', {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
if (res.ok) {
|
||||
alert('✅ Manually closed trades cleared from database')
|
||||
loadData() // Reload data
|
||||
} else {
|
||||
const error = await res.json()
|
||||
alert(`❌ Failed to clear: ${error.error}`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to clear trades:', error)
|
||||
alert('❌ Failed to clear trades')
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900 flex items-center justify-center">
|
||||
@@ -160,7 +183,16 @@ export default function AnalyticsPage() {
|
||||
{/* Position Summary */}
|
||||
{positions && (
|
||||
<div className="mb-8">
|
||||
<h2 className="text-xl font-bold text-white mb-4">📍 Current Positions</h2>
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h2 className="text-xl font-bold text-white">📍 Current Positions</h2>
|
||||
<button
|
||||
onClick={clearManuallyClosed}
|
||||
className="px-4 py-2 bg-red-600 hover:bg-red-700 rounded-lg text-white text-sm font-semibold transition-colors"
|
||||
title="Clear open trades from database if you manually closed them in Drift UI"
|
||||
>
|
||||
🗑️ Clear Manual Closes
|
||||
</button>
|
||||
</div>
|
||||
<div className="grid md:grid-cols-4 gap-4">
|
||||
<div className="bg-gray-800/50 backdrop-blur-sm rounded-xl p-6 border border-gray-700">
|
||||
<div className="text-sm text-gray-400 mb-1">Open Trades</div>
|
||||
|
||||
Reference in New Issue
Block a user