Remove demo data fallbacks - use only real Drift account data

- Updated Dashboard.tsx to remove demo data fallbacks
- Updated TradingHistory.tsx to use new Drift trading history endpoint
- Added getTradingHistory method to DriftTradingService
- Created new /api/drift/trading-history endpoint
- Removed fallback demo positions from getPositions method
- All UI components now show only real Drift account data or empty states
- No more hardcoded mock trades or positions
This commit is contained in:
mindesbunister
2025-07-13 00:38:24 +02:00
parent e985a9ec6f
commit 6e75a7175e
6 changed files with 315 additions and 143 deletions

View File

@@ -25,11 +25,11 @@ export default function Dashboard() {
try {
setLoading(true)
// Try to get Drift positions first
// Get Drift positions
const driftRes = await fetch('/api/drift/positions')
if (driftRes.ok) {
const driftData = await driftRes.json()
if (driftData.positions && driftData.positions.length > 0) {
if (driftData.positions) {
setPositions(driftData.positions)
// Calculate stats from Drift positions
@@ -41,7 +41,7 @@ export default function Dashboard() {
totalTrades: driftData.positions.length
}))
// Try to get account balance for account value
// Get account balance for account value
try {
const balanceRes = await fetch('/api/drift/balance')
if (balanceRes.ok) {
@@ -55,44 +55,39 @@ export default function Dashboard() {
console.warn('Could not fetch balance:', e)
}
} else {
// Fallback to legacy trading API
const res = await fetch('/api/trading')
if (res.ok) {
const data = await res.json()
setPositions(data.positions || [])
// Calculate some mock stats for demo
setStats({
totalPnL: 1247.50,
dailyPnL: 67.25,
winRate: 73.2,
totalTrades: 156,
accountValue: 10000
})
} else {
setError('Failed to load positions')
}
// No positions available - set empty state
setPositions([])
setStats({
totalPnL: 0,
dailyPnL: 0,
winRate: 0,
totalTrades: 0,
accountValue: 0
})
}
} else {
// Fallback to legacy trading API
const res = await fetch('/api/trading')
if (res.ok) {
const data = await res.json()
setPositions(data.positions || [])
// Calculate some mock stats for demo
setStats({
totalPnL: 1247.50,
dailyPnL: 67.25,
winRate: 73.2,
totalTrades: 156,
accountValue: 10000
})
} else {
setError('Failed to load positions')
}
// API failed - set empty state
setError('Failed to connect to Drift')
setPositions([])
setStats({
totalPnL: 0,
dailyPnL: 0,
winRate: 0,
totalTrades: 0,
accountValue: 0
})
}
} catch (e) {
setError('Error loading positions')
setError('Error connecting to Drift')
console.error('Error:', e)
setPositions([])
setStats({
totalPnL: 0,
dailyPnL: 0,
winRate: 0,
totalTrades: 0,
accountValue: 0
})
}
setLoading(false)
}
@@ -238,10 +233,10 @@ export default function Dashboard() {
<div className="flex items-center">
<div className="w-8 h-8 bg-gradient-to-br from-orange-400 to-orange-600 rounded-full flex items-center justify-center mr-3">
<span className="text-white text-xs font-bold">
{pos.symbol?.slice(0, 2) || 'BT'}
{pos.symbol?.slice(0, 2) || '--'}
</span>
</div>
<span className="font-medium text-white">{pos.symbol || 'BTC/USD'}</span>
<span className="font-medium text-white">{pos.symbol || '--'}</span>
</div>
</td>
<td className="py-4 px-4">
@@ -250,20 +245,20 @@ export default function Dashboard() {
? 'bg-green-500/20 text-green-400'
: 'bg-red-500/20 text-red-400'
}`}>
{pos.side || 'Long'}
{pos.side || '--'}
</span>
</td>
<td className="py-4 px-4 text-right font-mono text-gray-300">
{typeof pos.size === 'number' ? pos.size.toFixed(4) : (pos.size || '0.1 BTC')}
{typeof pos.size === 'number' ? pos.size.toFixed(4) : '--'}
</td>
<td className="py-4 px-4 text-right font-mono text-gray-300">
${typeof pos.entryPrice === 'number' ? pos.entryPrice.toFixed(2) : (pos.entryPrice || '45,230.00')}
${typeof pos.entryPrice === 'number' ? pos.entryPrice.toFixed(2) : '--'}
</td>
<td className="py-4 px-4 text-right">
<span className={`font-mono font-medium ${
(pos.unrealizedPnl || 125.50) >= 0 ? 'text-green-400' : 'text-red-400'
(pos.unrealizedPnl || 0) >= 0 ? 'text-green-400' : 'text-red-400'
}`}>
{(pos.unrealizedPnl || 125.50) >= 0 ? '+' : ''}${typeof pos.unrealizedPnl === 'number' ? pos.unrealizedPnl.toFixed(2) : '125.50'}
{(pos.unrealizedPnl || 0) >= 0 ? '+' : ''}${typeof pos.unrealizedPnl === 'number' ? pos.unrealizedPnl.toFixed(2) : '0.00'}
</span>
</td>
</tr>

View File

@@ -19,44 +19,26 @@ export default function TradingHistory() {
useEffect(() => {
async function fetchTrades() {
try {
const res = await fetch('/api/trading-history')
if (res.ok) {
const data = await res.json()
setTrades(data)
// Try Drift trading history first
const driftRes = await fetch('/api/drift/trading-history')
if (driftRes.ok) {
const data = await driftRes.json()
if (data.success && data.trades) {
setTrades(data.trades)
} else {
// No trades available
setTrades([])
}
} else {
// Mock data for demonstration
setTrades([
{
id: '1',
symbol: 'BTCUSD',
side: 'BUY',
amount: 0.1,
price: 45230.50,
status: 'FILLED',
executedAt: new Date().toISOString(),
pnl: 125.50
},
{
id: '2',
symbol: 'ETHUSD',
side: 'SELL',
amount: 2.5,
price: 2856.75,
status: 'FILLED',
executedAt: new Date(Date.now() - 3600000).toISOString(),
pnl: -67.25
},
{
id: '3',
symbol: 'SOLUSD',
side: 'BUY',
amount: 10,
price: 95.80,
status: 'FILLED',
executedAt: new Date(Date.now() - 7200000).toISOString(),
pnl: 89.75
}
])
// API failed - try fallback to local database
const res = await fetch('/api/trading-history')
if (res.ok) {
const data = await res.json()
setTrades(data || [])
} else {
// Both APIs failed - show empty state
setTrades([])
}
}
} catch (error) {
console.error('Failed to fetch trades:', error)