Gmx V2 Prices (#8)
* Update prices api * Update worker services in Program.cs
This commit is contained in:
@@ -11,6 +11,7 @@ using Managing.Domain.Trades;
|
||||
using Managing.Infrastructure.Evm.Abstractions;
|
||||
using Managing.Infrastructure.Evm.Models;
|
||||
using Managing.Infrastructure.Evm.Models.Gmx.v1;
|
||||
using Managing.Infrastructure.Evm.Models.Gmx.v2;
|
||||
using Managing.Infrastructure.Evm.Referentials;
|
||||
using Managing.Infrastructure.Evm.Services;
|
||||
using Managing.Infrastructure.Evm.Services.Gmx;
|
||||
@@ -38,6 +39,12 @@ public class EvmManager : IEvmManager
|
||||
private Dictionary<string, Dictionary<string, decimal>> _geckoPrices;
|
||||
private readonly GmxV2Service _gmxV2Service;
|
||||
|
||||
private readonly List<Ticker> _eligibleTickers = new List<Ticker>()
|
||||
{
|
||||
Ticker.BTC, Ticker.ETH, Ticker.LINK, Ticker.GMX, Ticker.SOL, Ticker.XRP, Ticker.ARB, Ticker.BNB, Ticker.AAVE,
|
||||
Ticker.PEPE, Ticker.DOGE, Ticker.UNI
|
||||
};
|
||||
|
||||
public EvmManager(IEnumerable<ISubgraphPrices> subgraphs)
|
||||
{
|
||||
var defaultChain = ChainService.GetEthereum();
|
||||
@@ -366,27 +373,24 @@ public class EvmManager : IEvmManager
|
||||
Timeframe timeframe)
|
||||
{
|
||||
string gmxTimeframe = GmxHelpers.GeTimeframe(timeframe);
|
||||
var gmxPrices = await _httpClient.GetFromJsonAsync<GmxPrices>(
|
||||
$"https://stats.gmx.io/api/candles/{ticker}?preferableChainId=42161&period={gmxTimeframe}&from={startDate.ToUnixTimestamp()}&preferableSource=fast");
|
||||
//var subgraph = _subgraphs.First(s => s.GetProvider() == subgraphProvider);
|
||||
//var prices = await subgraph.GetPrices(ticker, startDate, timeframe);
|
||||
|
||||
//if (prices == null)
|
||||
//{
|
||||
// foreach (var subgraphFallback in _subgraphs.Where(s => s.GetProvider() != subgraphProvider))
|
||||
// {
|
||||
// prices = await subgraphFallback.GetPrices(ticker, startDate, timeframe);
|
||||
|
||||
// if (prices != null)
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
var gmxPrices = await _httpClient.GetFromJsonAsync<GmxV2Prices>(
|
||||
$"https://arbitrum-api.gmxinfra.io/prices/candles?tokenSymbol={ticker}&period={gmxTimeframe}&limit=10000");
|
||||
|
||||
if (gmxPrices == null)
|
||||
return null;
|
||||
|
||||
gmxPrices.prices.RemoveAt(gmxPrices.prices.Count - 1);
|
||||
return gmxPrices.prices.Select(p => GmxMappers.Map(p, ticker, timeframe)).ToList();
|
||||
gmxPrices.Candles = gmxPrices.Candles.Where(p => p[0] >= startDate.ToUnixTimestamp()).ToList();
|
||||
gmxPrices.Candles.RemoveAt(gmxPrices.Candles.Count - 1);
|
||||
|
||||
var candles = new List<Candle>();
|
||||
var timeBetweenCandles = gmxPrices.Candles[0][0] - gmxPrices.Candles[1][0];
|
||||
for (int i = 0; i < gmxPrices.Candles.Count; i++)
|
||||
{
|
||||
var c = GmxV2Mappers.Map(gmxPrices.Candles[i], ticker, timeframe, (int)timeBetweenCandles);
|
||||
candles.Add(c);
|
||||
}
|
||||
|
||||
return candles.OrderBy(c => c.Date).ToList();
|
||||
}
|
||||
|
||||
public decimal GetVolume(SubgraphProvider subgraphProvider, Ticker ticker)
|
||||
@@ -403,9 +407,13 @@ public class EvmManager : IEvmManager
|
||||
|
||||
public async Task<List<Ticker>> GetAvailableTicker()
|
||||
{
|
||||
var subgraph = GetSubgraph(SubgraphProvider.Gbc);
|
||||
var pairs = await subgraph.GetTickers();
|
||||
return pairs.ToList();
|
||||
var tokenList = await _httpClient.GetFromJsonAsync<GmxV2TokenList>(
|
||||
"https://arbitrum-api.gmxinfra.io/tokens");
|
||||
|
||||
if (tokenList == null)
|
||||
return null;
|
||||
|
||||
return GmxV2Mappers.Map(tokenList).Where(t => _eligibleTickers.Contains(t)).ToList();
|
||||
}
|
||||
|
||||
public async Task<Candle> GetCandle(SubgraphProvider subgraphProvider, Ticker ticker)
|
||||
|
||||
Reference in New Issue
Block a user