Swap tokens
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Api.Models.Requests;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Domain.Accounts;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -89,6 +90,30 @@ namespace Managing.Api.Controllers
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Swaps tokens on GMX for a specific account.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the account to perform the swap for.</param>
|
||||
/// <param name="request">The swap request containing ticker symbols, amount, and order parameters.</param>
|
||||
/// <returns>The swap response with transaction details.</returns>
|
||||
[HttpPost]
|
||||
[Route("{name}/gmx-swap")]
|
||||
public async Task<ActionResult<SwapInfos>> SwapGmxTokens(string name, [FromBody] SwapTokensRequest request)
|
||||
{
|
||||
var user = await GetUser();
|
||||
var result = await _AccountService.SwapGmxTokensAsync(
|
||||
user,
|
||||
name,
|
||||
request.FromTicker,
|
||||
request.ToTicker,
|
||||
request.Amount,
|
||||
request.OrderType,
|
||||
request.TriggerRatio,
|
||||
request.AllowedSlippage
|
||||
);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a specific account by name for the authenticated user.
|
||||
/// </summary>
|
||||
|
||||
45
src/Managing.Api/Models/Requests/SwapTokensRequest.cs
Normal file
45
src/Managing.Api/Models/Requests/SwapTokensRequest.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Api.Models.Requests;
|
||||
|
||||
/// <summary>
|
||||
/// Request model for GMX token swap operations
|
||||
/// </summary>
|
||||
public class SwapTokensRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// The ticker symbol of the token to swap from
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Ticker FromTicker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ticker symbol of the token to swap to
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Ticker ToTicker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount to swap
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Range(0.000001, double.MaxValue, ErrorMessage = "Amount must be greater than 0")]
|
||||
public double Amount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The order type (market or limit)
|
||||
/// </summary>
|
||||
public string OrderType { get; set; } = "market";
|
||||
|
||||
/// <summary>
|
||||
/// The trigger ratio for limit orders (optional)
|
||||
/// </summary>
|
||||
public double? TriggerRatio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The allowed slippage percentage (default 0.5%)
|
||||
/// </summary>
|
||||
[Range(0, 100, ErrorMessage = "Allowed slippage must be between 0 and 100")]
|
||||
public double AllowedSlippage { get; set; } = 0.5;
|
||||
}
|
||||
Reference in New Issue
Block a user