diff --git a/src/Managing.Application/Abstractions/IMoneyManagementService.cs b/src/Managing.Application/Abstractions/IMoneyManagementService.cs index 0589874..15c3ed6 100644 --- a/src/Managing.Application/Abstractions/IMoneyManagementService.cs +++ b/src/Managing.Application/Abstractions/IMoneyManagementService.cs @@ -7,6 +7,7 @@ namespace Managing.Application.Abstractions { Task CreateOrUpdateMoneyManagement(User user, MoneyManagement request); Task GetMoneyMangement(User user, string name); + Task GetMoneyMangement(string name); IEnumerable GetMoneyMangements(User user); bool DeleteMoneyManagement(User user, string name); bool DeleteMoneyManagements(User user); diff --git a/src/Managing.Application/Bots/TradingBot.cs b/src/Managing.Application/Bots/TradingBot.cs index aba50e0..8dd4d85 100644 --- a/src/Managing.Application/Bots/TradingBot.cs +++ b/src/Managing.Application/Bots/TradingBot.cs @@ -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; diff --git a/src/Managing.Application/ManageBot/BotService.cs b/src/Managing.Application/ManageBot/BotService.cs index 671797f..906c17e 100644 --- a/src/Managing.Application/ManageBot/BotService.cs +++ b/src/Managing.Application/ManageBot/BotService.cs @@ -20,13 +20,14 @@ namespace Managing.Application.ManageBot private readonly IAccountService _accountService; private readonly ILogger _tradingBotLogger; private readonly ITradingService _tradingService; + private readonly IMoneyManagementService _moneyManagementService; private ConcurrentDictionary _botTasks = new ConcurrentDictionary(); public BotService(IBotRepository botRepository, IExchangeService exchangeService, IMessengerService messengerService, IAccountService accountService, ILogger 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) @@ -53,7 +55,7 @@ namespace Managing.Application.ManageBot if (backup != null) { backup.Data = data; - _botRepository.UpdateBackupBot(backup); + _botRepository.UpdateBackupBot(backup); } else { @@ -125,9 +127,11 @@ namespace Managing.Application.ManageBot break; case Enums.BotType.ScalpingBot: var scalpingBotData = JsonConvert.DeserializeObject(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(backupBot.Data); + var flippingMoneyManagement = + _moneyManagementService.GetMoneyMangement(flippingBotData.MoneyManagement.Name).Result; bot = CreateFlippingBot( flippingBotData.AccountName, - flippingBotData.MoneyManagement, + flippingMoneyManagement, backupBot.Name, flippingBotData.Ticker, flippingBotData.ScenarioName, diff --git a/src/Managing.Application/MoneyManagements/MoneyManagementService.cs b/src/Managing.Application/MoneyManagements/MoneyManagementService.cs index af1a65a..ba9521c 100644 --- a/src/Managing.Application/MoneyManagements/MoneyManagementService.cs +++ b/src/Managing.Application/MoneyManagements/MoneyManagementService.cs @@ -62,6 +62,11 @@ public class MoneyManagementService : IMoneyManagementService } } + public async Task GetMoneyMangement(string name) + { + return await _settingsRepository.GetMoneyManagement(name); + } + public IEnumerable GetMoneyMangements(User user) { try diff --git a/src/Managing.Application/Trading/OpenPositionCommandHandler.cs b/src/Managing.Application/Trading/OpenPositionCommandHandler.cs index 99d1d2b..3a91ad8 100644 --- a/src/Managing.Application/Trading/OpenPositionCommandHandler.cs +++ b/src/Managing.Application/Trading/OpenPositionCommandHandler.cs @@ -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 diff --git a/src/Managing.WebApp/src/pages/settingsPage/moneymanagement/moneyManagementModal.tsx b/src/Managing.WebApp/src/pages/settingsPage/moneymanagement/moneyManagementModal.tsx index 79043dd..044b1c5 100644 --- a/src/Managing.WebApp/src/pages/settingsPage/moneymanagement/moneyManagementModal.tsx +++ b/src/Managing.WebApp/src/pages/settingsPage/moneymanagement/moneyManagementModal.tsx @@ -75,8 +75,13 @@ const MoneyManagementModal: React.FC = ({ 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 = ({ + + + + = ({ list }) => {