Fix realized pnl on backtest save + add tests (not all passing)

This commit is contained in:
2025-11-14 02:38:15 +07:00
parent 1f7d914625
commit 460a7bd559
34 changed files with 6012 additions and 500 deletions

View File

@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="FluentAssertions" Version="8.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Managing.Common\Managing.Common.csproj" />
<ProjectReference Include="..\..\Managing.Core\Managing.Core.csproj" />
<ProjectReference Include="..\..\Managing.Domain\Managing.Domain.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,100 @@
using FluentAssertions;
using Managing.Common;
using Managing.Domain.Shared.Helpers;
using static Managing.Common.Enums;
using Xunit;
namespace Managing.Domain.SimpleTests;
/// <summary>
/// Simple tests for TradingBox methods that don't require complex domain objects.
/// Demonstrates the testing framework is properly configured.
/// </summary>
public class SimpleTradingBoxTests
{
[Fact]
public void GetHodlPercentage_WithPriceIncrease_CalculatesCorrectPercentage()
{
// Arrange
var candle1 = new Managing.Domain.Candles.Candle
{
Close = 100m,
Date = DateTime.UtcNow
};
var candle2 = new Managing.Domain.Candles.Candle
{
Close = 110m,
Date = DateTime.UtcNow.AddHours(1)
};
// Act
var result = TradingBox.GetHodlPercentage(candle1, candle2);
// Assert
result.Should().Be(10m);
}
[Fact]
public void GetHodlPercentage_WithPriceDecrease_CalculatesNegativePercentage()
{
// Arrange
var candle1 = new Managing.Domain.Candles.Candle
{
Close = 100m,
Date = DateTime.UtcNow
};
var candle2 = new Managing.Domain.Candles.Candle
{
Close = 90m,
Date = DateTime.UtcNow.AddHours(1)
};
// Act
var result = TradingBox.GetHodlPercentage(candle1, candle2);
// Assert
result.Should().Be(-10m);
}
[Fact]
public void GetGrowthFromInitalBalance_CalculatesCorrectGrowth()
{
// Arrange
var initialBalance = 1000m;
var finalPnl = 250m;
// Act
var result = TradingBox.GetGrowthFromInitalBalance(initialBalance, finalPnl);
// Assert
result.Should().Be(25m);
}
[Fact]
public void GetFeeAmount_CalculatesPercentageBasedFee()
{
// Arrange
var fee = 0.001m; // 0.1%
var amount = 10000m;
// Act
var result = TradingBox.GetFeeAmount(fee, amount);
// Assert
result.Should().Be(10m);
}
[Fact]
public void GetFeeAmount_WithEvmExchange_ReturnsFixedFee()
{
// Arrange
var fee = 0.001m;
var amount = 10000m;
// Act
var result = TradingBox.GetFeeAmount(fee, amount, Enums.TradingExchanges.Evm);
// Assert
result.Should().Be(fee);
}
}