Skip to content

Commit 568475e

Browse files
committed
fix: Post-merge cleanup and improvements
- Add missing TrendingUp/TrendingDown icon imports to performance cards - Simplify Hunter monitoring (remove UI warning spam) - Remove duplicate liquidation logging - Remove false 'WebSocket Closed' UI alerts - Hunter now quietly reconnects without alarming users - Status logged to console every 2 minutes only
1 parent 3a21847 commit 568475e

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

src/bot/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ logErrorWithTimestamp('⚠️ Position Manager failed to start:', error.message
474474

475475
// Connect hunter events to position manager and status broadcaster
476476
this.hunter.on('liquidationDetected', (liquidationEvent: any) => {
477-
logWithTimestamp(`💥 Liquidation: ${liquidationEvent.symbol} ${liquidationEvent.side} ${liquidationEvent.quantity}`);
477+
// Broadcast to UI and log activity (don't log to console - already logged in hunter.ts)
478478
this.statusBroadcaster.broadcastLiquidation(liquidationEvent);
479479
this.statusBroadcaster.logActivity(`Liquidation: ${liquidationEvent.symbol} ${liquidationEvent.side} ${liquidationEvent.quantity}`);
480480
});

src/components/PerformanceCardInline.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { useEffect, useState } from 'react';
44
import { Badge } from '@/components/ui/badge';
55
import { Skeleton } from '@/components/ui/skeleton';
6-
import { Clock } from 'lucide-react';
6+
import { Clock, TrendingUp, TrendingDown } from 'lucide-react';
77
import websocketService from '@/lib/services/websocketService';
88
import dataStore from '@/lib/services/dataStore';
99

src/components/SessionPerformanceCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { useEffect, useState } from 'react';
44
import { Badge } from '@/components/ui/badge';
55
import { Skeleton } from '@/components/ui/skeleton';
6-
import { Activity } from 'lucide-react';
6+
import { Activity, TrendingUp, TrendingDown } from 'lucide-react';
77
import websocketService from '@/lib/services/websocketService';
88

99
interface SessionPnL {

src/lib/bot/hunter.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class Hunter extends EventEmitter {
3939
private wsKeepAliveInterval: NodeJS.Timeout | null = null; // WebSocket keepalive ping timer
4040
private wsInactivityTimeout: NodeJS.Timeout | null = null; // WebSocket inactivity detector
4141
private lastLiquidationTime: number = Date.now(); // Track last liquidation received
42+
private statusLogInterval: NodeJS.Timeout | null = null; // Periodic status logging
4243

4344
constructor(config: Config, isHedgeMode: boolean = false) {
4445
super();
@@ -366,6 +367,19 @@ logWithTimestamp('Hunter: Running in paper mode without API keys - simulating li
366367

367368
// Start inactivity monitor - reconnect if no liquidations for 5 minutes
368369
this.startInactivityMonitor();
370+
371+
// Start periodic status logging - every 2 minutes
372+
this.statusLogInterval = setInterval(() => {
373+
const timeSinceLastLiq = Date.now() - this.lastLiquidationTime;
374+
const minutesInactive = Math.floor(timeSinceLastLiq / 60000);
375+
const secondsInactive = Math.floor((timeSinceLastLiq % 60000) / 1000);
376+
377+
if (minutesInactive >= 1) {
378+
logWithTimestamp(`📊 Hunter: Monitoring | Last liquidation: ${minutesInactive}m ${secondsInactive}s ago`);
379+
} else {
380+
logWithTimestamp(`📊 Hunter: Monitoring | Last liquidation: ${secondsInactive}s ago`);
381+
}
382+
}, 120000); // Every 2 minutes
369383
});
370384

371385
this.ws.on('ping', () => {
@@ -442,16 +456,7 @@ logWithTimestamp('Hunter: Running in paper mode without API keys - simulating li
442456
this.cleanupWebSocketTimers();
443457

444458
if (this.isRunning) {
445-
// Broadcast reconnection attempt to UI
446-
if (this.statusBroadcaster) {
447-
this.statusBroadcaster.broadcastWebSocketError(
448-
'Hunter WebSocket Closed',
449-
'Liquidation stream disconnected. Reconnecting in 5 seconds...',
450-
{
451-
component: 'Hunter',
452-
}
453-
);
454-
}
459+
// Reconnect silently - close events are often normal (like during inactivity reconnect)
455460
setTimeout(() => this.connectWebSocket(), 5000);
456461
}
457462
});
@@ -468,19 +473,7 @@ logWithTimestamp('Hunter: Running in paper mode without API keys - simulating li
468473
const timeSinceLastLiq = Date.now() - this.lastLiquidationTime;
469474
const minutesInactive = Math.floor(timeSinceLastLiq / 60000);
470475

471-
logWarnWithTimestamp(`⚠️ Hunter: No liquidations received for ${minutesInactive} minutes. Reconnecting...`);
472-
473-
// Broadcast warning to UI
474-
if (this.statusBroadcaster) {
475-
this.statusBroadcaster.broadcastWebSocketError(
476-
'Hunter Stream Inactive',
477-
`No liquidations received for ${minutesInactive} minutes. Reconnecting to ensure stream is alive...`,
478-
{
479-
component: 'Hunter',
480-
inactiveMinutes: minutesInactive,
481-
}
482-
);
483-
}
476+
logWarnWithTimestamp(`⚠️ Hunter: No liquidations for ${minutesInactive} minutes. Reconnecting stream...`);
484477

485478
// Force reconnection
486479
if (this.ws) {
@@ -500,6 +493,10 @@ logWithTimestamp('Hunter: Running in paper mode without API keys - simulating li
500493
clearTimeout(this.wsInactivityTimeout);
501494
this.wsInactivityTimeout = null;
502495
}
496+
if (this.statusLogInterval) {
497+
clearInterval(this.statusLogInterval);
498+
this.statusLogInterval = null;
499+
}
503500
}
504501

505502
private async handleLiquidationEvent(event: any): Promise<void> {
@@ -521,6 +518,10 @@ logWithTimestamp('Hunter: Running in paper mode without API keys - simulating li
521518
time: event.E, // Keep for backward compatibility
522519
};
523520

521+
// Log liquidation received with basic info
522+
const volumeUSDT = liquidation.qty * liquidation.price;
523+
logWithTimestamp(`💥 Liquidation: ${liquidation.symbol} ${liquidation.side} ${liquidation.qty.toFixed(4)} @ $${liquidation.price.toLocaleString()} ($${volumeUSDT.toFixed(2)})`);
524+
524525
// Check if threshold system is enabled globally and for this symbol
525526
const useThresholdSystem = this.config.global.useThresholdSystem === true &&
526527
this.config.symbols[liquidation.symbol]?.useThreshold === true;
@@ -537,8 +538,6 @@ logWithTimestamp('Hunter: Running in paper mode without API keys - simulating li
537538
const symbolConfig = this.config.symbols[liquidation.symbol];
538539
if (!symbolConfig) return; // Symbol not in config
539540

540-
const volumeUSDT = liquidation.qty * liquidation.price;
541-
542541
// Store liquidation in database (non-blocking)
543542
liquidationStorage.saveLiquidation(liquidation, volumeUSDT).catch(error => {
544543
logErrorWithTimestamp('Hunter: Failed to store liquidation:', error);

0 commit comments

Comments
 (0)