docker files fixes from liaqat
This commit is contained in:
98
src/Managing.Infrastructure.Web3/Services/TradaoService.cs
Normal file
98
src/Managing.Infrastructure.Web3/Services/TradaoService.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Domain.Statistics;
|
||||
using Managing.Domain.Trades;
|
||||
using Managing.Infrastructure.Evm.Models;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Services;
|
||||
|
||||
public class TradaoService : ITradaoService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public TradaoService()
|
||||
{
|
||||
_httpClient = new HttpClient(); ;
|
||||
}
|
||||
|
||||
public async Task<List<Trader>> GetBadTrader()
|
||||
{
|
||||
var bestTraders = await _httpClient.GetFromJsonAsync<TradaoList>($"https://api.tradao.xyz/v1/td/dashboard/42161/gmx/pnlTop/500/asc/2592000/0/?current=1&limit=500&order=asc&window=2592000&chain=42161&exchange=gmx&openPosition=0");
|
||||
|
||||
if (bestTraders == null || bestTraders.row.Count == 0)
|
||||
{
|
||||
return new List<Trader>();
|
||||
}
|
||||
|
||||
return await GetTraderDetails(bestTraders);
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<Trader>> GetBestTrader()
|
||||
{
|
||||
var bestTraders = await _httpClient.GetFromJsonAsync<TradaoList>($"https://api.tradao.xyz/v1/td/dashboard/42161/gmx/pnlTop/500/desc/2592000/0/?current=1&limit=500&order=desc&window=2592000&chain=42161&exchange=gmx&openPosition=0");
|
||||
|
||||
if (bestTraders == null || bestTraders.row.Count == 0)
|
||||
{
|
||||
return new List<Trader>();
|
||||
}
|
||||
|
||||
return await GetTraderDetails(bestTraders);
|
||||
}
|
||||
|
||||
public async Task<List<Trade>> GetTrades(string address)
|
||||
{
|
||||
var response = await _httpClient.GetFromJsonAsync<TradaoUserDetails>($"https://api.tradao.xyz/v1/td/trader/42161/gmx/insights/{address}");
|
||||
|
||||
var trades = new List<Trade>();
|
||||
|
||||
if (response == null) return trades;
|
||||
|
||||
foreach (var position in response.openPositions)
|
||||
{
|
||||
var trade = new Trade(
|
||||
DateTime.UtcNow,
|
||||
position.isLong ? Common.Enums.TradeDirection.Long : Common.Enums.TradeDirection.Short,
|
||||
Common.Enums.TradeStatus.Filled,
|
||||
Common.Enums.TradeType.Market,
|
||||
TokenService.GetTicker(position.indexTokenAddress),
|
||||
Convert.ToDecimal(position.collateral),
|
||||
Convert.ToDecimal(position.averagePrice),
|
||||
Convert.ToDecimal(position.position) / Convert.ToDecimal(position.collateral),
|
||||
address, position.liqPrice
|
||||
);
|
||||
|
||||
trades.Add(trade);
|
||||
}
|
||||
|
||||
return trades;
|
||||
}
|
||||
|
||||
private async Task<List<Trader>> GetTraderDetails(TradaoList traders)
|
||||
{
|
||||
var result = new List<Trader>();
|
||||
foreach (var trader in traders.row)
|
||||
{
|
||||
var response = await _httpClient.GetFromJsonAsync<TradaoUserDetails>($"https://api.tradao.xyz/v1/td/trader/42161/gmx/insights/{trader.user}");
|
||||
|
||||
if (response != null)
|
||||
result.Add(Map(response, trader.user));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Trader Map(TradaoUserDetails response, string address)
|
||||
{
|
||||
return new Trader
|
||||
{
|
||||
Address = address,
|
||||
Winrate = (int)(response.summary.winRate * 100),
|
||||
Pnl = Convert.ToDecimal(response.summary.pnl),
|
||||
TradeCount = response.summary.trades,
|
||||
AverageWin = Convert.ToDecimal(response.summary.averageWin),
|
||||
AverageLoss = Convert.ToDecimal(response.summary.averageLoss),
|
||||
Roi = Convert.ToDecimal(response.summary.roi)
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user