Add user to position + fix few things
This commit is contained in:
@@ -8,6 +8,7 @@ using Managing.Infrastructure.Evm.Models.Gmx.v2;
|
||||
using Managing.Infrastructure.Evm.Models.Proxy;
|
||||
using Nethereum.Web3;
|
||||
using Managing.Domain.MoneyManagements;
|
||||
using Managing.Domain.Users;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Services.Gmx;
|
||||
@@ -161,12 +162,13 @@ internal static class GmxV2Mappers
|
||||
{
|
||||
try
|
||||
{
|
||||
var position = new Position("",
|
||||
var position = new Position("", "",
|
||||
MiscExtensions.ParseEnum<TradeDirection>(gmxPosition.Direction),
|
||||
MiscExtensions.ParseEnum<Ticker>(gmxPosition.Ticker),
|
||||
new MoneyManagement(),
|
||||
PositionInitiator.User,
|
||||
gmxPosition.Date);
|
||||
gmxPosition.Date,
|
||||
new User());
|
||||
position.Open = Map(gmxPosition.Open);
|
||||
position.TakeProfit1 = Map(gmxPosition.TakeProfit1);
|
||||
position.StopLoss = Map(gmxPosition.StopLoss);
|
||||
@@ -174,15 +176,17 @@ internal static class GmxV2Mappers
|
||||
{
|
||||
Net = (decimal)gmxPosition.Pnl
|
||||
};
|
||||
|
||||
|
||||
position.Status = MiscExtensions.ParseEnum<PositionStatus>(gmxPosition.Status);
|
||||
positions.Add(position);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error mapping GMX position {gmxPosition?.ExchangeOrderId}: {ex.Message} \n StackTrace: {ex.StackTrace}");
|
||||
Console.WriteLine(
|
||||
$"Error mapping GMX position {gmxPosition?.ExchangeOrderId}: {ex.Message} \n StackTrace: {ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
return positions;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,17 +35,17 @@ namespace Managing.Infrastructure.Evm.Services
|
||||
endpoint = $"/{endpoint}";
|
||||
}
|
||||
|
||||
var url = $"{_settings.BaseUrl}privy{endpoint}";
|
||||
|
||||
var url = $"{_settings.BaseUrl}/api/privy{endpoint}";
|
||||
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.PostAsJsonAsync(url, payload, _jsonOptions);
|
||||
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
await HandleErrorResponse(response);
|
||||
}
|
||||
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<T>(_jsonOptions);
|
||||
}
|
||||
catch (Exception ex) when (!(ex is Web3ProxyException))
|
||||
@@ -62,7 +62,7 @@ namespace Managing.Infrastructure.Evm.Services
|
||||
endpoint = $"/{endpoint}";
|
||||
}
|
||||
|
||||
var url = $"{_settings.BaseUrl}privy{endpoint}";
|
||||
var url = $"{_settings.BaseUrl}/api/privy{endpoint}";
|
||||
|
||||
if (payload != null)
|
||||
{
|
||||
@@ -72,12 +72,12 @@ namespace Managing.Infrastructure.Evm.Services
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetAsync(url);
|
||||
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
await HandleErrorResponse(response);
|
||||
}
|
||||
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<T>(_jsonOptions);
|
||||
}
|
||||
catch (Exception ex) when (!(ex is Web3ProxyException))
|
||||
@@ -95,16 +95,16 @@ namespace Managing.Infrastructure.Evm.Services
|
||||
}
|
||||
|
||||
var url = $"{_settings.BaseUrl}/api/gmx{endpoint}";
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.PostAsJsonAsync(url, payload, _jsonOptions);
|
||||
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
await HandleErrorResponse(response);
|
||||
}
|
||||
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<T>(_jsonOptions);
|
||||
}
|
||||
catch (Exception ex) when (!(ex is Web3ProxyException))
|
||||
@@ -131,12 +131,12 @@ namespace Managing.Infrastructure.Evm.Services
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetAsync(url);
|
||||
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
await HandleErrorResponse(response);
|
||||
}
|
||||
|
||||
|
||||
return await response.Content.ReadFromJsonAsync<T>(_jsonOptions);
|
||||
}
|
||||
catch (Exception ex) when (!(ex is Web3ProxyException))
|
||||
@@ -149,25 +149,26 @@ namespace Managing.Infrastructure.Evm.Services
|
||||
private async Task HandleErrorResponse(HttpResponseMessage response)
|
||||
{
|
||||
var statusCode = (int)response.StatusCode;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// Try to parse as the Web3Proxy error format (success: false, error: string)
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
var errorResponse = await response.Content.ReadFromJsonAsync<Web3ProxyResponse>(_jsonOptions);
|
||||
|
||||
|
||||
if (errorResponse != null && !errorResponse.Success && !string.IsNullOrEmpty(errorResponse.Error))
|
||||
{
|
||||
// Handle the standard Web3Proxy error format
|
||||
throw new Web3ProxyException(errorResponse.Error);
|
||||
}
|
||||
|
||||
|
||||
// Fallback for other error formats
|
||||
try
|
||||
try
|
||||
{
|
||||
// Try to parse as structured error if it doesn't match the simple format
|
||||
var structuredErrorResponse = await response.Content.ReadFromJsonAsync<Web3ProxyErrorResponse>(_jsonOptions);
|
||||
|
||||
var structuredErrorResponse =
|
||||
await response.Content.ReadFromJsonAsync<Web3ProxyErrorResponse>(_jsonOptions);
|
||||
|
||||
if (structuredErrorResponse?.ErrorDetails != null)
|
||||
{
|
||||
structuredErrorResponse.ErrorDetails.StatusCode = statusCode;
|
||||
|
||||
Reference in New Issue
Block a user