Fix update money management

This commit is contained in:
2025-04-21 13:02:38 +02:00
parent 868c7bdb65
commit c571130bb0
7 changed files with 38 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ namespace Managing.Application.Abstractions
{
Task<MoneyManagement> CreateOrUpdateMoneyManagement(User user, MoneyManagement request);
Task<MoneyManagement> GetMoneyMangement(User user, string name);
Task<MoneyManagement> GetMoneyMangement(string name);
IEnumerable<MoneyManagement> GetMoneyMangements(User user);
bool DeleteMoneyManagement(User user, string name);
bool DeleteMoneyManagements(User user);

View File

@@ -775,7 +775,7 @@ public class TradingBot : Bot, ITradingBot
Signals = data.Signals;
Positions = data.Positions;
WalletBalances = data.WalletBalances;
MoneyManagement = data.MoneyManagement;
// MoneyManagement = data.MoneyManagement; => loaded from database
Timeframe = data.Timeframe;
Ticker = data.Ticker;
ScenarioName = data.ScenarioName;

View File

@@ -20,13 +20,14 @@ namespace Managing.Application.ManageBot
private readonly IAccountService _accountService;
private readonly ILogger<TradingBot> _tradingBotLogger;
private readonly ITradingService _tradingService;
private readonly IMoneyManagementService _moneyManagementService;
private ConcurrentDictionary<string, BotTaskWrapper> _botTasks =
new ConcurrentDictionary<string, BotTaskWrapper>();
public BotService(IBotRepository botRepository, IExchangeService exchangeService,
IMessengerService messengerService, IAccountService accountService, ILogger<TradingBot> tradingBotLogger,
ITradingService tradingService)
ITradingService tradingService, IMoneyManagementService moneyManagementService)
{
_botRepository = botRepository;
_exchangeService = exchangeService;
@@ -34,6 +35,7 @@ namespace Managing.Application.ManageBot
_accountService = accountService;
_tradingBotLogger = tradingBotLogger;
_tradingService = tradingService;
_moneyManagementService = moneyManagementService;
}
public async void SaveOrUpdateBotBackup(BotBackup botBackup)
@@ -125,9 +127,11 @@ namespace Managing.Application.ManageBot
break;
case Enums.BotType.ScalpingBot:
var scalpingBotData = JsonConvert.DeserializeObject<TradingBotBackup>(backupBot.Data);
var scalpingMoneyManagement =
_moneyManagementService.GetMoneyMangement(scalpingBotData.MoneyManagement.Name).Result;
bot = CreateScalpingBot(
scalpingBotData.AccountName,
scalpingBotData.MoneyManagement,
scalpingMoneyManagement,
backupBot.Name,
scalpingBotData.Ticker,
scalpingBotData.ScenarioName,
@@ -137,9 +141,11 @@ namespace Managing.Application.ManageBot
break;
case Enums.BotType.FlippingBot:
var flippingBotData = JsonConvert.DeserializeObject<TradingBotBackup>(backupBot.Data);
var flippingMoneyManagement =
_moneyManagementService.GetMoneyMangement(flippingBotData.MoneyManagement.Name).Result;
bot = CreateFlippingBot(
flippingBotData.AccountName,
flippingBotData.MoneyManagement,
flippingMoneyManagement,
backupBot.Name,
flippingBotData.Ticker,
flippingBotData.ScenarioName,

View File

@@ -62,6 +62,11 @@ public class MoneyManagementService : IMoneyManagementService
}
}
public async Task<MoneyManagement> GetMoneyMangement(string name)
{
return await _settingsRepository.GetMoneyManagement(name);
}
public IEnumerable<MoneyManagement> GetMoneyMangements(User user)
{
try

View File

@@ -86,7 +86,7 @@ namespace Managing.Application.Trading
request.MoneyManagement.Leverage,
TradeType.StopLoss,
request.Date,
TradeStatus.PendingOpen);
TradeStatus.Requested);
position.StopLoss.Fee = TradingHelpers.GetFeeAmount(fee,
position.StopLoss.Price * position.StopLoss.Quantity, account.Exchange);
@@ -100,7 +100,7 @@ namespace Managing.Application.Trading
request.MoneyManagement.Leverage,
TradeType.TakeProfit,
request.Date,
TradeStatus.PendingOpen);
TradeStatus.Requested);
position.Status = IsOpenTradeHandled(position.Open.Status, account.Exchange)
? position.Status

View File

@@ -75,8 +75,13 @@ const MoneyManagementModal: React.FC<IMoneyManagementModalProps> = ({
setLeverage(e.target.value)
}
function onBalanceAtRiskChange(e: any) {
setBalanceAtRisk(e.target.value)
}
useEffect(() => {
if (moneyManagement) {
console.log(moneyManagement)
setBalanceAtRisk(moneyManagement.balanceAtRisk * 100)
setTakeProfit(moneyManagement.takeProfit * 100)
setStopLoss(moneyManagement.stopLoss * 100)
@@ -131,6 +136,18 @@ const MoneyManagementModal: React.FC<IMoneyManagementModalProps> = ({
</select>
</FormInput>
<FormInput label="Balance at risk" htmlFor="balanceAtRisk">
<Slider
id="balanceAtRisk"
value={balanceAtRisk}
onChange={onBalanceAtRiskChange}
step="1"
max="100"
suffixValue="%"
disabled={disableInputs}
></Slider>
</FormInput>
<FormInput label="TP%" htmlFor="takeProfit">
<Slider
id="takeProfit"

View File

@@ -127,8 +127,8 @@ const MoneyManagementTable: React.FC<IMoneyManagementList> = ({ list }) => {
<div className="flex flex-wrap">
<Table columns={columns} data={rows} />
<MoneyManagementModal
isOpen={showModal}
toggleModal={toggleModal}
showModal={showModal}
onClose={toggleModal}
moneyManagement={selectedRow}
/>
</div>