Implements React + TypeScript UI with Vite and Tailwind CSS. Features dashboard with real-time WebSocket updates, backtesting page, model management interface, trading controls, and settings. Includes state management with Zustand, API integration with Axios/TanStack Query, and interactive charts with Recharts.
22 lines
591 B
TypeScript
22 lines
591 B
TypeScript
import { useEffect } from 'react';
|
|
import { webSocketService } from '@/services/websocket';
|
|
import type { WebSocketEventType } from '@/services/types';
|
|
|
|
export function useWebSocket() {
|
|
useEffect(() => {
|
|
webSocketService.connect();
|
|
return () => webSocketService.disconnect();
|
|
}, []);
|
|
|
|
const subscribe = <T = unknown>(
|
|
eventType: WebSocketEventType,
|
|
handler: (data: T) => void
|
|
): (() => void) => {
|
|
return webSocketService.subscribe<T>(eventType, handler);
|
|
};
|
|
|
|
const isConnected = webSocketService.getConnectionStatus();
|
|
|
|
return { subscribe, isConnected };
|
|
}
|