GMX v2 - Trading (#7)
* Move PrivateKeys.cs * Update gitignore * Update gitignore * updt * Extract GmxServiceTests.cs * Refact * update todo * Update code * Fix hashdata * Replace static token hashed datas * Set allowance * Add get orders * Add get orders tests * Add ignore * add close orders * revert * Add get gas limit * Start increasePosition. Todo: Finish GetExecutionFee and estimateGas * little refact * Update gitignore * Fix namespaces and clean repo * Add tests samples * Add execution fee * Add increase position * Handle backtest on the frontend * Add tests * Update increase * Test increase * fix increase * Fix size * Start get position * Update get positions * Fix get position * Update rpc and trade mappers * Finish close position * Fix leverage
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
namespace Managing.Domain.Evm;
|
||||
namespace Managing.Infrastructure.Evm.Models;
|
||||
|
||||
public class GeckoToken
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Numerics;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx;
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx.v1;
|
||||
|
||||
public class GmxOrder
|
||||
{
|
||||
@@ -16,4 +16,4 @@ public class GmxOrder
|
||||
public bool TriggerAboveThreshold { get; internal set; }
|
||||
public GmxOrderType Type { get; internal set; }
|
||||
public BigInteger Index { get; internal set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx;
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx.v1;
|
||||
|
||||
public class GmxOrderIndexes
|
||||
{
|
||||
public int SwapIndex { get; set; }
|
||||
public int IncreaseIndex { get; set; }
|
||||
public int DecreaseIndex { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx;
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx.v1;
|
||||
|
||||
public class GmxPosition
|
||||
{
|
||||
@@ -16,4 +16,4 @@ public class GmxPosition
|
||||
public BigInteger HasProfit { get; set; }
|
||||
public BigInteger Delta { get; set; }
|
||||
public BigInteger LastIncreasedTime { get; internal set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx;
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx.v1;
|
||||
|
||||
public class GmxPrices
|
||||
{
|
||||
@@ -7,8 +7,6 @@ public class GmxPrices
|
||||
public int updatedAt { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class GmxOhlc
|
||||
{
|
||||
public int t { get; set; }
|
||||
@@ -16,4 +14,4 @@ public class GmxOhlc
|
||||
public double c { get; set; }
|
||||
public double h { get; set; }
|
||||
public double l { get; set; }
|
||||
}
|
||||
}
|
||||
31
src/Managing.Infrastructure.Web3/Models/Gmx/v2/GmxTicker.cs
Normal file
31
src/Managing.Infrastructure.Web3/Models/Gmx/v2/GmxTicker.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx.v2;
|
||||
|
||||
public class GmxTicker
|
||||
{
|
||||
[JsonProperty("tokenAddress", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonPropertyName("tokenAddress")]
|
||||
public string TokenAddress { get; set; }
|
||||
|
||||
[JsonProperty("tokenSymbol", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonPropertyName("tokenSymbol")]
|
||||
public string TokenSymbol { get; set; }
|
||||
|
||||
[JsonProperty("minPrice", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonPropertyName("minPrice")]
|
||||
public string MinPrice { get; set; }
|
||||
|
||||
[JsonProperty("maxPrice", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonPropertyName("maxPrice")]
|
||||
public string MaxPrice { get; set; }
|
||||
|
||||
[JsonProperty("updatedAt", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonPropertyName("updatedAt")]
|
||||
public object UpdatedAt { get; set; }
|
||||
|
||||
[JsonProperty("timestamp", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonPropertyName("timestamp")]
|
||||
public int Timestamp { get; set; }
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Numerics;
|
||||
using Managing.ABI.GmxV2.Reader.ContractDefinition;
|
||||
using Managing.Infrastructure.Evm.Services.Gmx;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx.v2;
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx.v2;
|
||||
|
||||
public class GmxV2ExecutionFee
|
||||
{
|
||||
public string FeeUsd { get; set; }
|
||||
public BigInteger FeeAmount { get; set; }
|
||||
public GmxTokenData NativeToken { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx.v2;
|
||||
|
||||
public class GmxV2GasLimit
|
||||
{
|
||||
public BigInteger DepositSingleToken { get; set; }
|
||||
public BigInteger DepositMultiToken { get; set; }
|
||||
public BigInteger WithdrawalMultiToken { get; set; }
|
||||
public BigInteger Shift { get; set; }
|
||||
public BigInteger SingleSwap { get; set; }
|
||||
public BigInteger SwapOrder { get; set; }
|
||||
public BigInteger IncreaseOrder { get; set; }
|
||||
public BigInteger DecreaseOrder { get; set; }
|
||||
public BigInteger EstimatedGasFeeBaseAmount { get; set; }
|
||||
public BigInteger EstimatedGasFeePerOraclePrice { get; set; }
|
||||
public BigInteger EstimatedFeeMultiplierFactor { get; set; }
|
||||
}
|
||||
66
src/Managing.Infrastructure.Web3/Models/Gmx/v2/GmxV2Order.cs
Normal file
66
src/Managing.Infrastructure.Web3/Models/Gmx/v2/GmxV2Order.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.Numerics;
|
||||
using Managing.ABI.GmxV2.Reader.ContractDefinition;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx.v2;
|
||||
|
||||
public class GmxV2Order
|
||||
{
|
||||
public byte[] Key { get; set; }
|
||||
public string Account { get; set; }
|
||||
public string Receiver { get; set; }
|
||||
public string CallbackContract { get; set; }
|
||||
public string MarketAddress { get; set; }
|
||||
public string InitialCollateralTokenAddress { get; set; }
|
||||
public List<string> SwapPath { get; set; }
|
||||
public BigInteger SizeDeltaUsd { get; set; }
|
||||
public BigInteger InitialCollateralDeltaAmount { get; set; }
|
||||
public BigInteger ContractTriggerPrice { get; set; }
|
||||
public BigInteger ContractAcceptablePrice { get; set; }
|
||||
public BigInteger ExecutionFee { get; set; }
|
||||
public BigInteger CallbackGasLimit { get; set; }
|
||||
public BigInteger MinOutputAmount { get; set; }
|
||||
public BigInteger UpdatedAtBlock { get; set; }
|
||||
public bool IsLong { get; set; }
|
||||
public bool ShouldUnwrapNativeToken { get; set; }
|
||||
public bool IsFrozen { get; set; }
|
||||
public GmxV2OrderType OrderType { get; set; }
|
||||
public GmxV2DecreasePositionSwapType DecreasePositionSwapType { get; set; }
|
||||
public Props Data { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
}
|
||||
|
||||
public enum GmxV2DecreasePositionSwapType
|
||||
{
|
||||
NoSwap = 0,
|
||||
SwapPnlTokenToCollateralToken = 1,
|
||||
SwapCollateralTokenToPnlToken = 2
|
||||
}
|
||||
|
||||
public enum GmxV2OrderType
|
||||
{
|
||||
// the order will be cancelled if the minOutputAmount cannot be fulfilled
|
||||
MarketSwap = 0,
|
||||
|
||||
// @dev LimitSwap: swap token A to token B if the minOutputAmount can be fulfilled
|
||||
LimitSwap = 1,
|
||||
|
||||
// @dev MarketIncrease: increase position at the current market price
|
||||
// the order will be cancelled if the position cannot be increased at the acceptablePrice
|
||||
MarketIncrease = 2,
|
||||
|
||||
// @dev LimitIncrease: increase position if the triggerPrice is reached and the acceptablePrice can be fulfilled
|
||||
LimitIncrease = 3,
|
||||
|
||||
// @dev MarketDecrease: decrease position at the current market price
|
||||
// the order will be cancelled if the position cannot be decreased at the acceptablePrice
|
||||
MarketDecrease = 4,
|
||||
|
||||
// @dev LimitDecrease: decrease position if the triggerPrice is reached and the acceptablePrice can be fulfilled
|
||||
LimitDecrease = 5,
|
||||
|
||||
// @dev StopLossDecrease: decrease position if the triggerPrice is reached and the acceptablePrice can be fulfilled
|
||||
StopLossDecrease = 6,
|
||||
|
||||
// @dev Liquidation: allows liquidation of positions if the criteria for liquidation are met
|
||||
Liquidation = 7
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Numerics;
|
||||
using Managing.Infrastructure.Evm.Services.Gmx;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Models.Gmx.v2;
|
||||
|
||||
public class GmxV2Position
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string? ContractKey { get; set; }
|
||||
public string Account { get; set; }
|
||||
public string MarketAddress { get; set; }
|
||||
public string CollateralTokenAddress { get; set; }
|
||||
public BigInteger SizeInUsd { get; set; }
|
||||
public BigInteger SizeInTokens { get; set; }
|
||||
public BigInteger CollateralAmount { get; set; }
|
||||
public BigInteger PendingBorrowingFeesUsd { get; set; }
|
||||
public BigInteger IncreasedAtTime { get; set; }
|
||||
public BigInteger DecreasedAtTime { get; set; }
|
||||
public bool IsLong { get; set; }
|
||||
public BigInteger FundingFeeAmount { get; set; }
|
||||
public BigInteger ClaimableLongTokenAmount { get; set; }
|
||||
public BigInteger ClaimableShortTokenAmount { get; set; }
|
||||
public bool? IsOpening { get; set; }
|
||||
public PendingPositionUpdate PendingUpdate { get; set; }
|
||||
public string Data { get; set; }
|
||||
public GmxMarketInfo MarketInfo { get; set; }
|
||||
public GmxToken TokenData { get; set; }
|
||||
}
|
||||
|
||||
public class PendingPositionUpdate
|
||||
{
|
||||
public bool IsIncrease { get; set; }
|
||||
public string PositionKey { get; set; }
|
||||
public BigInteger SizeDeltaUsd { get; set; }
|
||||
public BigInteger SizeDeltaInTokens { get; set; }
|
||||
public BigInteger CollateralDeltaAmount { get; set; }
|
||||
public int UpdatedAt { get; set; }
|
||||
public BigInteger UpdatedAtTime { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user