docker files fixes from liaqat
This commit is contained in:
139
src/Managing.Infrastructure.Web3/Services/Gmx/GmxHelpers.cs
Normal file
139
src/Managing.Infrastructure.Web3/Services/Gmx/GmxHelpers.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using Managing.Domain.Trades;
|
||||
using Managing.Infrastructure.Evm.Models.Gmx;
|
||||
using Managing.Infrastructure.Evm.Referentials;
|
||||
using Nethereum.Web3;
|
||||
using System.Numerics;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Services.Gmx;
|
||||
|
||||
public static class GmxHelpers
|
||||
{
|
||||
|
||||
public static decimal GetQuantityForLeverage(decimal quantity, decimal? leverage)
|
||||
{
|
||||
return leverage.HasValue ? leverage.Value * quantity : quantity;
|
||||
}
|
||||
|
||||
public static (List<string> CollateralTokens, List<string> IndexTokens, List<bool> IsLong) GetPositionQueryData(List<string> contractAddress)
|
||||
{
|
||||
var collateralToken = new List<string>();
|
||||
var indexTokens = new List<string>();
|
||||
var isLongs = new List<bool>();
|
||||
|
||||
foreach (var token in contractAddress)
|
||||
{
|
||||
collateralToken.Add(token);
|
||||
indexTokens.Add(token);
|
||||
isLongs.Add(true);
|
||||
}
|
||||
|
||||
foreach (var token in contractAddress)
|
||||
{
|
||||
collateralToken.Add(Arbitrum.Address.USDC);
|
||||
indexTokens.Add(token);
|
||||
isLongs.Add(false);
|
||||
}
|
||||
|
||||
return (collateralToken, indexTokens, isLongs);
|
||||
}
|
||||
|
||||
public static List<BigInteger> GetIndexesRange(int lastIndex)
|
||||
{
|
||||
var indexes = new List<BigInteger>();
|
||||
|
||||
var limit = 15;
|
||||
var from = (lastIndex - limit) < 0 ? 0 : lastIndex - limit;
|
||||
|
||||
for (int i = from; i <= lastIndex; i++)
|
||||
{
|
||||
indexes.Add(new BigInteger(i));
|
||||
}
|
||||
|
||||
return indexes;
|
||||
}
|
||||
|
||||
public static BigInteger GetAcceptablePrice(decimal price, bool isLong)
|
||||
{
|
||||
decimal priceBasisPoints;
|
||||
var basisPointDivisor = 10000m;
|
||||
var allowedSlippage = 34m;
|
||||
var toDecimal = 30;
|
||||
|
||||
if (isLong)
|
||||
{
|
||||
priceBasisPoints = basisPointDivisor - allowedSlippage;
|
||||
}
|
||||
else
|
||||
{
|
||||
priceBasisPoints = basisPointDivisor + allowedSlippage;
|
||||
}
|
||||
var test = Web3.Convert.ToWei(price, toDecimal) * new BigInteger(priceBasisPoints);
|
||||
|
||||
var priceLimit = test / Web3.Convert.ToWei(basisPointDivisor, 0);
|
||||
|
||||
return priceLimit;
|
||||
}
|
||||
|
||||
internal static BigInteger? GetGasLimit()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal static List<Trade> Map(List<GmxOrder> orders, Ticker ticker)
|
||||
{
|
||||
return orders.ConvertAll(order => Map(order, ticker));
|
||||
|
||||
}
|
||||
private static Trade Map(GmxOrder order, Ticker ticker)
|
||||
{
|
||||
var trade = new Trade(DateTime.UtcNow,
|
||||
order.IsLong ? TradeDirection.Short : TradeDirection.Long,
|
||||
TradeStatus.Requested,
|
||||
GetTradeType(order.IsLong, order.TriggerAboveThreshold),
|
||||
ticker,
|
||||
Convert.ToDecimal(order.SizeDelta),
|
||||
Convert.ToDecimal(order.TriggerPrice),
|
||||
null,
|
||||
"", ""
|
||||
);
|
||||
|
||||
return trade;
|
||||
}
|
||||
|
||||
public static bool GetTriggerAboveThreshold(bool isLong, TradeType tradeType)
|
||||
{
|
||||
if ((isLong && tradeType == TradeType.TakeProfit) ||
|
||||
(!isLong && tradeType == TradeType.StopLoss))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static TradeType GetTradeType(bool isLong, bool isAboveThreshold)
|
||||
{
|
||||
if ((isLong && isAboveThreshold) ||
|
||||
(!isLong && !isAboveThreshold))
|
||||
{
|
||||
return TradeType.TakeProfit;
|
||||
}
|
||||
|
||||
return TradeType.StopLoss;
|
||||
}
|
||||
|
||||
internal static string GeTimeframe(Timeframe timeframe)
|
||||
{
|
||||
return timeframe switch
|
||||
{
|
||||
Timeframe.FiveMinutes => "5m",
|
||||
Timeframe.FifteenMinutes => "15m",
|
||||
Timeframe.ThirtyMinutes => "30m",
|
||||
Timeframe.OneHour => "1h",
|
||||
Timeframe.FourHour => "4h",
|
||||
Timeframe.OneDay => "1d",
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user