Update backtest bundle

This commit is contained in:
2025-07-22 00:14:50 +07:00
parent 27c1e9d1ba
commit 5427c8a971
2 changed files with 41 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
import React, {useEffect, useRef, useState} from 'react';
import {BundleBacktestRequest, LightBacktestResponse} from '../../generated/ManagingApiTypes';
import {BundleBacktestRequest, LightBacktestResponse, Ticker, Timeframe} from '../../generated/ManagingApiTypes';
import {BacktestClient} from '../../generated/ManagingApi';
import useApiUrlStore from '../../app/store/apiStore';
import Toast from '../../components/mollecules/Toast/Toast';
@@ -31,21 +31,32 @@ const BundleRequestModal: React.FC<BundleRequestModalProps> = ({ open, onClose,
const client = new BacktestClient({} as any, apiUrl);
const res = await client.backtest_GetBacktestsByRequestId(bundle.requestId);
if (!res) return [];
return res.map((b: any) => ({
id: b.id,
config: b.config,
finalPnl: b.finalPnl,
winRate: b.winRate,
growthPercentage: b.growthPercentage,
hodlPercentage: b.hodlPercentage,
startDate: b.startDate,
endDate: b.endDate,
maxDrawdown: b.maxDrawdown ?? null,
fees: b.fees,
sharpeRatio: b.sharpeRatio ?? null,
score: b.score ?? 0,
scoreMessage: b.scoreMessage ?? '',
}));
return res.map((b: any) => {
// Map enums for ticker and timeframe
if (b.config) {
if (typeof b.config.ticker === 'number') {
b.config.ticker = Ticker[b.config.ticker as keyof typeof Ticker];
}
if (typeof b.config.timeframe === 'number') {
b.config.timeframe = Timeframe[b.config.timeframe as keyof typeof Timeframe];
}
}
return {
id: b.id,
config: b.config,
finalPnl: b.finalPnl,
winRate: b.winRate,
growthPercentage: b.growthPercentage,
hodlPercentage: b.hodlPercentage,
startDate: b.startDate,
endDate: b.endDate,
maxDrawdown: b.maxDrawdown ?? null,
fees: b.fees,
sharpeRatio: b.sharpeRatio ?? null,
score: b.score ?? 0,
scoreMessage: b.scoreMessage ?? '',
};
});
},
enabled: !!open && !!bundle,
refetchOnWindowFocus: false,
@@ -78,6 +89,19 @@ const BundleRequestModal: React.FC<BundleRequestModalProps> = ({ open, onClose,
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];