Bundle from worker to grain
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, {useState} from 'react';
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import {AccountClient, BacktestClient} from '../../generated/ManagingApi';
|
||||
import type {
|
||||
MoneyManagementRequest,
|
||||
@@ -61,9 +61,6 @@ const BacktestBundleForm: React.FC = () => {
|
||||
const { data: accounts, isSuccess } = useQuery({
|
||||
queryFn: async () => {
|
||||
const fetchedAccounts = await accountClient.account_GetAccounts();
|
||||
if (fetchedAccounts.length > 0 && accountName === 'default') {
|
||||
setAccountName(fetchedAccounts[0].name);
|
||||
}
|
||||
return fetchedAccounts;
|
||||
},
|
||||
queryKey: ['accounts'],
|
||||
@@ -88,13 +85,20 @@ const BacktestBundleForm: React.FC = () => {
|
||||
const [flipOnlyInProfit, setFlipOnlyInProfit] = useState(false);
|
||||
const [closeEarly, setCloseEarly] = useState(false);
|
||||
const [startingCapital, setStartingCapital] = useState(10000);
|
||||
const [accountName, setAccountName] = useState(accounts?.[0]?.name ?? '');
|
||||
const [accountName, setAccountName] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [success, setSuccess] = useState<string | null>(null);
|
||||
|
||||
const { scenario, setCustomScenario } = useCustomScenario();
|
||||
|
||||
// Set account name when accounts are loaded
|
||||
useEffect(() => {
|
||||
if (accounts && accounts.length > 0 && !accountName) {
|
||||
setAccountName(accounts[0].name);
|
||||
}
|
||||
}, [accounts, accountName]);
|
||||
|
||||
// Placeholder for cart summary
|
||||
const totalBacktests =
|
||||
moneyManagementVariants.length * timeRangeVariants.length * (selectedAssets.length || 1);
|
||||
@@ -159,6 +163,7 @@ const BacktestBundleForm: React.FC = () => {
|
||||
const client = new BacktestClient({} as any, apiUrl);
|
||||
const requests = generateRequests();
|
||||
if (!strategyName) throw new Error('Strategy name is required');
|
||||
if (!accountName) throw new Error('Account selection is required');
|
||||
if (requests.length === 0) throw new Error('No backtest variants to run');
|
||||
await client.backtest_RunBundle({ name: strategyName, requests });
|
||||
setSuccess('Bundle backtest started successfully!');
|
||||
@@ -195,12 +200,17 @@ const BacktestBundleForm: React.FC = () => {
|
||||
className="select select-bordered w-full"
|
||||
value={accountName}
|
||||
onChange={e => setAccountName(e.target.value)}
|
||||
disabled={!accounts || accounts.length === 0}
|
||||
>
|
||||
{accounts?.map(account => (
|
||||
<option key={account.name} value={account.name}>
|
||||
{account.name}
|
||||
</option>
|
||||
))}
|
||||
{!accounts || accounts.length === 0 ? (
|
||||
<option value="">Loading accounts...</option>
|
||||
) : (
|
||||
accounts.map(account => (
|
||||
<option key={account.name} value={account.name}>
|
||||
{account.name}
|
||||
</option>
|
||||
))
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user