Fix position
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -182,9 +182,11 @@ public class EvmManager : IEvmManager
|
|||||||
var web3 = new Web3(chain.RpcUrl);
|
var web3 = new Web3(chain.RpcUrl);
|
||||||
var etherBalance = Web3.Convert.FromWei(await web3.Eth.GetBalance.SendRequestAsync(account));
|
var etherBalance = Web3.Convert.FromWei(await web3.Eth.GetBalance.SendRequestAsync(account));
|
||||||
var lastCandle = await GetCandle(Ticker.ETH);
|
var lastCandle = await GetCandle(Ticker.ETH);
|
||||||
|
|
||||||
return new EvmBalance()
|
return new EvmBalance()
|
||||||
{ Balance = etherBalance, Price = lastCandle.Close, TokenName = "ETH", Value = etherBalance * lastCandle.Close };
|
{
|
||||||
|
Balance = etherBalance, Price = lastCandle.Close, TokenName = "ETH", Value = etherBalance * lastCandle.Close
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<EvmBalance>> GetAllBalances(Chain chain, string publicAddress)
|
public async Task<List<EvmBalance>> GetAllBalances(Chain chain, string publicAddress)
|
||||||
@@ -401,10 +403,10 @@ public class EvmManager : IEvmManager
|
|||||||
var lastCandles = await GetCandles(ticker, DateTime.UtcNow.AddMinutes(-5),
|
var lastCandles = await GetCandles(ticker, DateTime.UtcNow.AddMinutes(-5),
|
||||||
Timeframe.OneMinute);
|
Timeframe.OneMinute);
|
||||||
cachedCandle = lastCandles.Last();
|
cachedCandle = lastCandles.Last();
|
||||||
|
|
||||||
_cacheService.SaveValue(key, cachedCandle, TimeSpan.FromMinutes(5));
|
_cacheService.SaveValue(key, cachedCandle, TimeSpan.FromMinutes(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
return cachedCandle;
|
return cachedCandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,7 +501,7 @@ public class EvmManager : IEvmManager
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = await _web3ProxyService.CallGmxServiceAsync<dynamic>("/cancel-orders",
|
var response = await _web3ProxyService.CallGmxServiceAsync<Web3ProxyResponse>("/cancel-orders",
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
account = account.Key,
|
account = account.Key,
|
||||||
@@ -507,7 +509,7 @@ public class EvmManager : IEvmManager
|
|||||||
ticker = ticker.ToString()
|
ticker = ticker.ToString()
|
||||||
});
|
});
|
||||||
|
|
||||||
return response.success ?? false;
|
return response.Success;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -727,11 +729,11 @@ public class EvmManager : IEvmManager
|
|||||||
var result = await _web3ProxyService.GetGmxServiceAsync<GetGmxPositionsResponse>(
|
var result = await _web3ProxyService.GetGmxServiceAsync<GetGmxPositionsResponse>(
|
||||||
"/positions",
|
"/positions",
|
||||||
new { account = account.Key });
|
new { account = account.Key });
|
||||||
|
|
||||||
|
|
||||||
return GmxV2Mappers.Map(result.Positions);
|
return GmxV2Mappers.Map(result.Positions);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ export class Orders extends Module {
|
|||||||
skipSimulation: true,
|
skipSimulation: true,
|
||||||
indexToken: marketInfo.indexToken,
|
indexToken: marketInfo.indexToken,
|
||||||
tokensData,
|
tokensData,
|
||||||
autoCancel: autoCancelOrdersLimit > 0,
|
autoCancel: autoCancelOrdersLimit > 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ export const openGmxPositionImpl = async (
|
|||||||
allowedSlippageBps: 100, // 1% slippage
|
allowedSlippageBps: 100, // 1% slippage
|
||||||
leverage: leverageBps,
|
leverage: leverageBps,
|
||||||
skipSimulation: true,
|
skipSimulation: true,
|
||||||
limitPrice: limitPrice,
|
limitPrice: null,
|
||||||
referralCodeForTxn: encodeReferralCode("kaigen_ai"),
|
referralCodeForTxn: encodeReferralCode("kaigen_ai"),
|
||||||
stopLossPrice: stopLossPrice ? numberToBigint(stopLossPrice, 30) : undefined,
|
stopLossPrice: stopLossPrice ? numberToBigint(stopLossPrice, 30) : undefined,
|
||||||
takeProfitPrice: takeProfitPrice ? numberToBigint(takeProfitPrice, 30) : undefined
|
takeProfitPrice: takeProfitPrice ? numberToBigint(takeProfitPrice, 30) : undefined
|
||||||
@@ -440,7 +440,7 @@ export const closeGmxPositionImpl = async (
|
|||||||
sizeDeltaInTokens: position.sizeInTokens,
|
sizeDeltaInTokens: position.sizeInTokens,
|
||||||
collateralDeltaUsd: position.remainingCollateralAmount,
|
collateralDeltaUsd: position.remainingCollateralAmount,
|
||||||
collateralDeltaAmount: position.remainingCollateralAmount,
|
collateralDeltaAmount: position.remainingCollateralAmount,
|
||||||
acceptablePriceDeltaBps: 0n,
|
acceptablePriceDeltaBps: 30n,
|
||||||
recommendedAcceptablePriceDeltaBps: 0n,
|
recommendedAcceptablePriceDeltaBps: 0n,
|
||||||
estimatedPnl: 0n,
|
estimatedPnl: 0n,
|
||||||
estimatedPnlPercentage: 0n,
|
estimatedPnlPercentage: 0n,
|
||||||
@@ -464,7 +464,7 @@ export const closeGmxPositionImpl = async (
|
|||||||
indexPrice: 0n,
|
indexPrice: 0n,
|
||||||
collateralPrice: 0n,
|
collateralPrice: 0n,
|
||||||
acceptablePrice: position.markPrice,
|
acceptablePrice: position.markPrice,
|
||||||
triggerOrderType: OrderType.MarketDecrease,
|
triggerOrderType: OrderType.LimitDecrease,
|
||||||
triggerPrice: position.markPrice,
|
triggerPrice: position.markPrice,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,7 +475,7 @@ export const closeGmxPositionImpl = async (
|
|||||||
marketsInfoData,
|
marketsInfoData,
|
||||||
tokensData,
|
tokensData,
|
||||||
isLong: direction === TradeDirection.Short,
|
isLong: direction === TradeDirection.Short,
|
||||||
allowedSlippage: 0,
|
allowedSlippage: 30,
|
||||||
decreaseAmounts,
|
decreaseAmounts,
|
||||||
collateralToken: position.marketInfo.shortToken,
|
collateralToken: position.marketInfo.shortToken,
|
||||||
referralCodeForTxn: encodeReferralCode("kaigen_ai"),
|
referralCodeForTxn: encodeReferralCode("kaigen_ai"),
|
||||||
|
|||||||
Reference in New Issue
Block a user