Add bundle version number on the backtest name
This commit is contained in:
@@ -18,8 +18,6 @@ import {
|
||||
import useApiUrlStore from '../../app/store/apiStore';
|
||||
import Toast from '../../components/mollecules/Toast/Toast';
|
||||
import {useQuery} from '@tanstack/react-query';
|
||||
import * as signalR from '@microsoft/signalr';
|
||||
import AuthorizedApiBase from '../../generated/AuthorizedApiBase';
|
||||
import BacktestTable from '../../components/organism/Backtest/backtestTable';
|
||||
import FormInput from '../../components/mollecules/FormInput/FormInput';
|
||||
import CustomScenario from '../../components/organism/CustomScenario/CustomScenario';
|
||||
@@ -337,73 +335,6 @@ const BundleRequestModal: React.FC<BundleRequestModalProps> = ({
|
||||
if (queryBacktests) setBacktests(queryBacktests);
|
||||
}, [queryBacktests]);
|
||||
|
||||
// SignalR live updates for existing bundles
|
||||
useEffect(() => {
|
||||
if (!open || !bundle) return;
|
||||
if (bundle.status !== 'Pending' && bundle.status !== 'Running') return;
|
||||
let connection: any = null;
|
||||
let connectionId: string = '';
|
||||
let unsubscribed = false;
|
||||
(async () => {
|
||||
try {
|
||||
connection = new signalR.HubConnectionBuilder()
|
||||
.withUrl(`${apiUrl.replace(/\/$/, '')}/backtestHub`)
|
||||
.withAutomaticReconnect()
|
||||
.build();
|
||||
await connection.start();
|
||||
connectionId = connection.connectionId;
|
||||
// Subscribe to bundle updates
|
||||
const authBase = new AuthorizedApiBase({} as any);
|
||||
let fetchOptions: any = {
|
||||
method: 'POST',
|
||||
headers: { 'X-SignalR-ConnectionId': connectionId },
|
||||
};
|
||||
fetchOptions = await authBase.transformOptions(fetchOptions);
|
||||
await fetch(`${apiUrl}/backtest/Bundle/Subscribe?requestId=${bundle.requestId}`, fetchOptions);
|
||||
connection.on('BundleBacktestUpdate', (result: LightBacktestResponse) => {
|
||||
// Map enums if needed
|
||||
if (result.config) {
|
||||
if (typeof result.config.ticker === 'number') {
|
||||
result.config.ticker = Ticker[result.config.ticker as keyof typeof Ticker];
|
||||
} else if (typeof result.config.ticker === 'string' && Ticker[result.config.ticker as keyof typeof Ticker]) {
|
||||
result.config.ticker = Ticker[result.config.ticker as keyof typeof Ticker];
|
||||
}
|
||||
if (typeof result.config.timeframe === 'number') {
|
||||
result.config.timeframe = Timeframe[result.config.timeframe as keyof typeof Timeframe];
|
||||
} else if (typeof result.config.timeframe === 'string' && Timeframe[result.config.timeframe as keyof typeof Timeframe]) {
|
||||
result.config.timeframe = Timeframe[result.config.timeframe as keyof typeof Timeframe];
|
||||
}
|
||||
}
|
||||
setBacktests((prev) => {
|
||||
if (prev.some((b) => b.id === result.id)) return prev;
|
||||
return [...prev, result];
|
||||
});
|
||||
});
|
||||
signalRRef.current = connection;
|
||||
} catch (e: any) {
|
||||
new Toast('Failed to subscribe to live updates', false);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
unsubscribed = true;
|
||||
if (connection && connectionId) {
|
||||
(async () => {
|
||||
const authBase = new AuthorizedApiBase({} as any);
|
||||
let fetchOptions: any = {
|
||||
method: 'POST',
|
||||
headers: { 'X-SignalR-ConnectionId': connectionId },
|
||||
};
|
||||
fetchOptions = await authBase.transformOptions(fetchOptions);
|
||||
await fetch(`${apiUrl}/backtest/Bundle/Unsubscribe?requestId=${bundle.requestId}`, fetchOptions);
|
||||
})();
|
||||
}
|
||||
if (signalRRef.current) {
|
||||
signalRRef.current.stop();
|
||||
signalRRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [open, bundle, apiUrl]);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
// If viewing an existing bundle
|
||||
|
||||
Reference in New Issue
Block a user