Add ETH and USDC balance check before start/restart bot and autoswap
This commit is contained in:
@@ -33,7 +33,7 @@ public interface IExchangeProcessor
|
||||
decimal GetVolume(Account account, Ticker ticker);
|
||||
Task<List<Trade>> GetTrades(Account account, Ticker ticker);
|
||||
Task<bool> CancelOrder(Account account, Ticker ticker);
|
||||
decimal GetFee(Account account, bool isForPaperTrading = false);
|
||||
Task<decimal> GetFee(Account account, bool isForPaperTrading = false);
|
||||
Task<Candle> GetCandle(Account account, Ticker ticker, DateTime date);
|
||||
Task<decimal> GetQuantityInPosition(Account account, Ticker ticker);
|
||||
Orderbook GetOrderbook(Account account, Ticker ticker);
|
||||
|
||||
@@ -51,6 +51,21 @@ namespace Managing.Infrastructure.Exchanges
|
||||
reduceOnly ? TradeStatus.PendingOpen : TradeStatus.Filled);
|
||||
}
|
||||
|
||||
// Check gas fees for EVM exchanges before opening position
|
||||
if (IsEvmExchange(account))
|
||||
{
|
||||
var gasFeeUsd = await GetFee(account);
|
||||
if (gasFeeUsd > 0.5m)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
$"Gas fee too high for position opening: {gasFeeUsd:F2} USD (threshold: 0.5 USD). Cancelling position opening.");
|
||||
|
||||
// Return a cancelled trade
|
||||
return BuildEmptyTrade(ticker, price, quantity, direction, leverage, tradeType, currentDate.Value,
|
||||
TradeStatus.Cancelled);
|
||||
}
|
||||
}
|
||||
|
||||
var processor = GetProcessor(account);
|
||||
return await processor.OpenTrade(account, ticker, direction, price, quantity, leverage, tradeType,
|
||||
reduceOnly, isForPaperTrading, currentDate, ioc, stopLossPrice, takeProfitPrice);
|
||||
@@ -242,10 +257,10 @@ namespace Managing.Infrastructure.Exchanges
|
||||
return await processor.GetBalance(account);
|
||||
}
|
||||
|
||||
public decimal GetFee(Account account, bool isForPaperTrading = false)
|
||||
public async Task<decimal> GetFee(Account account, bool isForPaperTrading = false)
|
||||
{
|
||||
var processor = GetProcessor(account);
|
||||
return processor.GetFee(account);
|
||||
return await processor.GetFee(account);
|
||||
}
|
||||
|
||||
public async Task<decimal> GetPrice(Account account, Ticker ticker, DateTime date)
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Managing.Infrastructure.Exchanges.Exchanges
|
||||
public abstract Task<decimal> GetBalance(Account account, bool isForPaperTrading = false);
|
||||
public abstract Task<Candle> GetCandle(Account account, Ticker ticker, DateTime date);
|
||||
public abstract Task<List<Candle>> GetCandles(Account account, Ticker ticker, DateTime startDate, Timeframe interval);
|
||||
public abstract decimal GetFee(Account account, bool isForPaperTrading = false);
|
||||
public abstract Task<decimal> GetFee(Account account, bool isForPaperTrading = false);
|
||||
public abstract Task<decimal> GetPrice(Account account, Ticker ticker, DateTime date);
|
||||
public abstract Task<decimal> GetCurrentPrice(Account account, Ticker ticker);
|
||||
public abstract Task<decimal> GetQuantityInPosition(Account account, Ticker ticker);
|
||||
|
||||
@@ -78,9 +78,9 @@ public class EvmProcessor : BaseProcessor
|
||||
return await _evmManager.GetCandles(ticker, startDate, interval, isFirstCall);
|
||||
}
|
||||
|
||||
public override decimal GetFee(Account account, bool isForPaperTrading = false)
|
||||
public override async Task<decimal> GetFee(Account account, bool isForPaperTrading = false)
|
||||
{
|
||||
return _evmManager.GetFee(Constants.Chains.Arbitrum).Result;
|
||||
return await _evmManager.GetFee(Constants.Chains.Arbitrum);
|
||||
}
|
||||
|
||||
public override async Task<decimal> GetPrice(Account account, Ticker ticker, DateTime date)
|
||||
|
||||
Reference in New Issue
Block a user