Fix backtest delete and save
This commit is contained in:
@@ -47,11 +47,11 @@ public class BacktestRepository : IBacktestRepository
|
|||||||
|
|
||||||
public void DeleteBacktestByIdForUser(User user, string id)
|
public void DeleteBacktestByIdForUser(User user, string id)
|
||||||
{
|
{
|
||||||
var backtest = _backtestRepository.FindById(id);
|
var backtest = _backtestRepository.FindOne(b => b.Identifier == id);
|
||||||
|
|
||||||
if (backtest != null && backtest.User != null && backtest.User.Name == user.Name)
|
if (backtest != null && backtest.User != null && backtest.User.Name == user.Name)
|
||||||
{
|
{
|
||||||
_backtestRepository.DeleteById(id);
|
_backtestRepository.DeleteById(backtest.Id.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,5 +22,6 @@ namespace Managing.Infrastructure.Databases.MongoDb.Collections
|
|||||||
public UserDto User { get; set; }
|
public UserDto User { get; set; }
|
||||||
public PerformanceMetrics Statistics { get; set; }
|
public PerformanceMetrics Statistics { get; set; }
|
||||||
public double Score { get; set; }
|
public double Score { get; set; }
|
||||||
|
public string Identifier { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,6 @@ using Managing.Domain.Users;
|
|||||||
using Managing.Domain.Workers;
|
using Managing.Domain.Workers;
|
||||||
using Managing.Domain.Workflows.Synthetics;
|
using Managing.Domain.Workflows.Synthetics;
|
||||||
using Managing.Infrastructure.Databases.MongoDb.Collections;
|
using Managing.Infrastructure.Databases.MongoDb.Collections;
|
||||||
using MongoDB.Bson;
|
|
||||||
using static Managing.Common.Enums;
|
using static Managing.Common.Enums;
|
||||||
|
|
||||||
namespace Managing.Infrastructure.Databases.MongoDb;
|
namespace Managing.Infrastructure.Databases.MongoDb;
|
||||||
@@ -145,7 +144,7 @@ public static class MongoMappers
|
|||||||
WinRate = b.WinRate,
|
WinRate = b.WinRate,
|
||||||
GrowthPercentage = b.GrowthPercentage,
|
GrowthPercentage = b.GrowthPercentage,
|
||||||
HodlPercentage = b.HodlPercentage,
|
HodlPercentage = b.HodlPercentage,
|
||||||
Id = b.Id.ToString(),
|
Id = b.Identifier,
|
||||||
OptimizedMoneyManagement = Map(b.OptimizedMoneyManagement),
|
OptimizedMoneyManagement = Map(b.OptimizedMoneyManagement),
|
||||||
User = Map(b.User),
|
User = Map(b.User),
|
||||||
Statistics = b.Statistics,
|
Statistics = b.Statistics,
|
||||||
@@ -164,7 +163,7 @@ public static class MongoMappers
|
|||||||
|
|
||||||
return new BacktestDto
|
return new BacktestDto
|
||||||
{
|
{
|
||||||
Id = (!string.IsNullOrEmpty(result.Id)) ? ObjectId.Parse(result.Id) : ObjectId.GenerateNewId(),
|
Identifier = result.Id,
|
||||||
FinalPnl = result.FinalPnl,
|
FinalPnl = result.FinalPnl,
|
||||||
WinRate = result.WinRate,
|
WinRate = result.WinRate,
|
||||||
GrowthPercentage = result.GrowthPercentage,
|
GrowthPercentage = result.GrowthPercentage,
|
||||||
|
|||||||
@@ -636,7 +636,7 @@ const UnifiedTradingModal: React.FC<UnifiedTradingModalProps> = ({
|
|||||||
scenarioName: customScenario ? undefined : form.scenarioName,
|
scenarioName: customScenario ? undefined : form.scenarioName,
|
||||||
timeframe: form.timeframe,
|
timeframe: form.timeframe,
|
||||||
isForWatchingOnly: form.isForWatchingOnly || false,
|
isForWatchingOnly: form.isForWatchingOnly || false,
|
||||||
flipPosition: false, // Default to false since we're only using isForWatchingOnly checkbox
|
flipPosition: form.flipPosition || false,
|
||||||
cooldownPeriod: form.cooldownPeriod,
|
cooldownPeriod: form.cooldownPeriod,
|
||||||
maxLossStreak: form.maxLossStreak,
|
maxLossStreak: form.maxLossStreak,
|
||||||
maxPositionTimeHours: form.maxPositionTimeHours,
|
maxPositionTimeHours: form.maxPositionTimeHours,
|
||||||
@@ -700,7 +700,7 @@ const UnifiedTradingModal: React.FC<UnifiedTradingModalProps> = ({
|
|||||||
useForDynamicStopLoss: form.useForDynamicStopLoss ?? true,
|
useForDynamicStopLoss: form.useForDynamicStopLoss ?? true,
|
||||||
moneyManagementName: showCustomMoneyManagement ? undefined : selectedMoneyManagement,
|
moneyManagementName: showCustomMoneyManagement ? undefined : selectedMoneyManagement,
|
||||||
moneyManagement: customMoneyManagement,
|
moneyManagement: customMoneyManagement,
|
||||||
flipPosition: form.isForWatchingOnly ?? false,
|
flipPosition: form.flipPosition || false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const request: RunBacktestRequest = {
|
const request: RunBacktestRequest = {
|
||||||
@@ -1129,6 +1129,25 @@ const UnifiedTradingModal: React.FC<UnifiedTradingModalProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Trading Options */}
|
{/* Trading Options */}
|
||||||
|
<FormInput
|
||||||
|
label={
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
Enable Position Flipping
|
||||||
|
<div className="tooltip tooltip-top" data-tip="Allow the bot to flip between long and short positions based on signals. More aggressive trading strategy">
|
||||||
|
<span className="badge badge-info badge-xs">i</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
htmlFor="flipPosition"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="toggle toggle-primary"
|
||||||
|
{...register('flipPosition')}
|
||||||
|
/>
|
||||||
|
</FormInput>
|
||||||
|
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
<FormInput
|
<FormInput
|
||||||
label={
|
label={
|
||||||
@@ -1167,26 +1186,6 @@ const UnifiedTradingModal: React.FC<UnifiedTradingModalProps> = ({
|
|||||||
</FormInput>
|
</FormInput>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Position Flipping (bot modes only) */}
|
|
||||||
{mode !== 'backtest' && (
|
|
||||||
<FormInput
|
|
||||||
label={
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
Enable Position Flipping
|
|
||||||
<div className="tooltip tooltip-top" data-tip="Allow the bot to flip between long and short positions based on signals. More aggressive trading strategy">
|
|
||||||
<span className="badge badge-info badge-xs">i</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
htmlFor="flipPosition"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
className="toggle toggle-primary"
|
|
||||||
{...register('flipPosition')}
|
|
||||||
/>
|
|
||||||
</FormInput>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Save Option (backtest mode only) */}
|
{/* Save Option (backtest mode only) */}
|
||||||
{mode === 'backtest' && (
|
{mode === 'backtest' && (
|
||||||
|
|||||||
Reference in New Issue
Block a user