63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
using Managing.Domain.MoneyManagements;
|
|
using Managing.Domain.Shared.Helpers;
|
|
using Xunit;
|
|
using static Managing.Common.Enums;
|
|
|
|
namespace Managing.Application.Tests
|
|
{
|
|
public class RiskHelpersTests
|
|
{
|
|
private readonly MoneyManagement _moneyManagement;
|
|
public RiskHelpersTests()
|
|
{
|
|
_moneyManagement = new MoneyManagement()
|
|
{
|
|
BalanceAtRisk = 0.05m,
|
|
Leverage = 1,
|
|
Timeframe = Timeframe.OneDay,
|
|
StopLoss = 0.008m,
|
|
TakeProfit = 0.02m
|
|
};
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(1000, 992)]
|
|
public void Should_Return_Correct_Stop_Loss_Price_For_Long(decimal price, decimal expectedResult)
|
|
{
|
|
var stopLossPrice = RiskHelpers.GetStopLossPrice(TradeDirection.Long, price, _moneyManagement);
|
|
Assert.Equal(expectedResult, stopLossPrice);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(1000, 1008)]
|
|
public void Should_Return_Correct_Stop_Loss_Price_For_Short(decimal price, decimal expectedResult)
|
|
{
|
|
var stopLossPrice = RiskHelpers.GetStopLossPrice(TradeDirection.Short, price, _moneyManagement);
|
|
Assert.Equal(expectedResult, stopLossPrice);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(1000, 980)]
|
|
public void Should_Return_Correct_Take_Profit_Price_For_Short(decimal price, decimal expectedResult)
|
|
{
|
|
var stopLossPrice = RiskHelpers.GetTakeProfitPrice(TradeDirection.Short, price, _moneyManagement);
|
|
Assert.Equal(expectedResult, stopLossPrice);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(1000, 1020)]
|
|
public void Should_Return_Correct_Take_Profit_Price_For_Long(decimal price, decimal expectedResult)
|
|
{
|
|
var stopLossPrice = RiskHelpers.GetTakeProfitPrice(TradeDirection.Long, price, _moneyManagement);
|
|
Assert.Equal(expectedResult, stopLossPrice);
|
|
}
|
|
|
|
[Fact]
|
|
public void Test()
|
|
{
|
|
const decimal test = (decimal)34523.4352;
|
|
Assert.Equal((decimal)34523.4, Math.Round(test, 1));
|
|
}
|
|
}
|
|
}
|