Refactor user settings management to remove IsGmxEnabled and DefaultExchange from updatable fields, introducing GmxSlippage instead. Update UserController, UserService, and related DTOs to reflect these changes, ensuring proper handling of user settings. Adjust database schema and migrations to accommodate the new GmxSlippage property, enhancing user customization options for trading configurations.

This commit is contained in:
2025-12-30 07:19:08 +07:00
parent aa3b06bbe4
commit 21d87efeee
23 changed files with 1908 additions and 32 deletions

View File

@@ -73,6 +73,10 @@ namespace Managing.Application.Trading.Handlers
var stopLossPrice = RiskHelpers.GetStopLossPrice(request.Direction, openPrice, request.MoneyManagement);
var takeProfitPrice = RiskHelpers.GetTakeProfitPrice(request.Direction, openPrice, request.MoneyManagement);
// Get user's slippage setting from IndicatorComboConfig
var config = TradingBox.CreateConfigFromUserSettings(request.User);
var allowedSlippage = request.User.GmxSlippage ?? config.GmxSlippage;
var trade = await exchangeService.OpenTrade(
account,
request.Ticker,
@@ -84,7 +88,8 @@ namespace Managing.Application.Trading.Handlers
isForPaperTrading: request.IsForPaperTrading,
currentDate: request.Date,
stopLossPrice: stopLossPrice,
takeProfitPrice: takeProfitPrice);
takeProfitPrice: takeProfitPrice,
allowedSlippage: allowedSlippage);
position.Open = trade;

View File

@@ -455,7 +455,7 @@ public class TradingService : ITradingService
}
public async Task<SwapInfos> SwapGmxTokensAsync(User user, string accountName, Ticker fromTicker, Ticker toTicker,
double amount, string orderType = "market", double? triggerRatio = null, double allowedSlippage = 0.5)
double amount, string orderType = "market", double? triggerRatio = null, double? allowedSlippage = null)
{
// Get the account for the user
var account = await _accountService.GetAccountByUser(user, accountName, true, false);
@@ -473,6 +473,14 @@ public class TradingService : ITradingService
try
{
// Get user's config to access default slippage value
var config = TradingBox.CreateConfigFromUserSettings(user);
// Use provided allowedSlippage if specified, otherwise use user's GmxSlippage setting, or default from IndicatorComboConfig
var slippageToUse = (double)(allowedSlippage.HasValue
? (decimal)allowedSlippage.Value
: (user.GmxSlippage ?? config.GmxSlippage));
// Call the Web3ProxyService to swap GMX tokens
var swapInfos = await _web3ProxyService.SwapGmxTokensAsync(
account.Key,
@@ -481,7 +489,7 @@ public class TradingService : ITradingService
amount,
orderType,
triggerRatio,
allowedSlippage
slippageToUse
);
return swapInfos;