Remove logs for position update on pnl
This commit is contained in:
@@ -812,11 +812,14 @@ public class TradingBotBase : ITradingBot
|
|||||||
|
|
||||||
var currentTime = Config.IsForBacktest ? lastCandle.Date : DateTime.UtcNow;
|
var currentTime = Config.IsForBacktest ? lastCandle.Date : DateTime.UtcNow;
|
||||||
var currentPnl = positionForSignal.ProfitAndLoss?.Net ?? 0;
|
var currentPnl = positionForSignal.ProfitAndLoss?.Net ?? 0;
|
||||||
var pnlPercentage = TradingBox.CalculatePnLPercentage(currentPnl, positionForSignal.Open.Price, positionForSignal.Open.Quantity);
|
var pnlPercentage = TradingBox.CalculatePnLPercentage(currentPnl, positionForSignal.Open.Price,
|
||||||
|
positionForSignal.Open.Quantity);
|
||||||
|
|
||||||
var isPositionInProfit = TradingBox.IsPositionInProfit(positionForSignal.Open.Price, lastCandle.Close, positionForSignal.OriginDirection);
|
var isPositionInProfit = TradingBox.IsPositionInProfit(positionForSignal.Open.Price, lastCandle.Close,
|
||||||
|
positionForSignal.OriginDirection);
|
||||||
|
|
||||||
var hasExceededTimeLimit = TradingBox.HasPositionExceededTimeLimit(positionForSignal.Open.Date, currentTime, Config.MaxPositionTimeHours);
|
var hasExceededTimeLimit = TradingBox.HasPositionExceededTimeLimit(positionForSignal.Open.Date,
|
||||||
|
currentTime, Config.MaxPositionTimeHours);
|
||||||
|
|
||||||
if (hasExceededTimeLimit)
|
if (hasExceededTimeLimit)
|
||||||
{
|
{
|
||||||
@@ -1241,7 +1244,7 @@ public class TradingBotBase : ITradingBot
|
|||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var canOpen = TradingBox.CheckLossStreak(recentPositions, Config.MaxLossStreak, signal.Direction);
|
var canOpen = TradingBox.CheckLossStreak(recentPositions, Config.MaxLossStreak, signal.Direction);
|
||||||
|
|
||||||
if (!canOpen)
|
if (!canOpen)
|
||||||
{
|
{
|
||||||
var lastPosition = recentPositions.First();
|
var lastPosition = recentPositions.First();
|
||||||
@@ -1699,7 +1702,7 @@ public class TradingBotBase : ITradingBot
|
|||||||
closingPrice = position.OriginDirection == TradeDirection.Long
|
closingPrice = position.OriginDirection == TradeDirection.Long
|
||||||
? minPriceRecent // For LONG, SL hits at the low
|
? minPriceRecent // For LONG, SL hits at the low
|
||||||
: maxPriceRecent; // For SHORT, SL hits at the high
|
: maxPriceRecent; // For SHORT, SL hits at the high
|
||||||
|
|
||||||
position.StopLoss.Price = closingPrice;
|
position.StopLoss.Price = closingPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1738,7 +1741,7 @@ public class TradingBotBase : ITradingBot
|
|||||||
closingPrice = position.OriginDirection == TradeDirection.Long
|
closingPrice = position.OriginDirection == TradeDirection.Long
|
||||||
? maxPriceRecent // For LONG, TP hits at the high
|
? maxPriceRecent // For LONG, TP hits at the high
|
||||||
: minPriceRecent; // FOR SHORT, TP hits at the low
|
: minPriceRecent; // FOR SHORT, TP hits at the low
|
||||||
|
|
||||||
position.TakeProfit1.Price = closingPrice;
|
position.TakeProfit1.Price = closingPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1852,7 +1855,8 @@ public class TradingBotBase : ITradingBot
|
|||||||
var entryPrice = position.Open.Price;
|
var entryPrice = position.Open.Price;
|
||||||
var positionSize = TradingBox.CalculatePositionSize(position.Open.Quantity, position.Open.Leverage);
|
var positionSize = TradingBox.CalculatePositionSize(position.Open.Quantity, position.Open.Leverage);
|
||||||
|
|
||||||
decimal pnl = TradingBox.CalculatePnL(entryPrice, closingPrice, position.Open.Quantity, position.Open.Leverage, position.OriginDirection);
|
decimal pnl = TradingBox.CalculatePnL(entryPrice, closingPrice, position.Open.Quantity,
|
||||||
|
position.Open.Leverage, position.OriginDirection);
|
||||||
|
|
||||||
if (position.ProfitAndLoss == null)
|
if (position.ProfitAndLoss == null)
|
||||||
{
|
{
|
||||||
@@ -1880,18 +1884,10 @@ public class TradingBotBase : ITradingBot
|
|||||||
$"Total Fees: `${position.GasFees + position.UiFees:F2}`\n" +
|
$"Total Fees: `${position.GasFees + position.UiFees:F2}`\n" +
|
||||||
$"Net P&L (after fees): `${position.ProfitAndLoss.Net:F2}`";
|
$"Net P&L (after fees): `${position.ProfitAndLoss.Net:F2}`";
|
||||||
|
|
||||||
if (Config.IsForBacktest)
|
if (!Config.IsForBacktest)
|
||||||
{
|
|
||||||
// For backtest, use Console.WriteLine to see in test output
|
|
||||||
Console.WriteLine(logMessage);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
await LogDebug(logMessage);
|
await LogDebug(logMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fees are now tracked separately in UiFees and GasFees properties
|
|
||||||
// No need to subtract fees from PnL as they're tracked separately
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SkipCandleBasedCalculation:
|
SkipCandleBasedCalculation:
|
||||||
@@ -2281,7 +2277,6 @@ public class TradingBotBase : ITradingBot
|
|||||||
/// <param name="position">The position to check</param>
|
/// <param name="position">The position to check</param>
|
||||||
/// <param name="currentTime">The current time to compare against</param>
|
/// <param name="currentTime">The current time to compare against</param>
|
||||||
/// <returns>True if the position has exceeded the time limit, false otherwise</returns>
|
/// <returns>True if the position has exceeded the time limit, false otherwise</returns>
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the trading bot configuration with new settings.
|
/// Updates the trading bot configuration with new settings.
|
||||||
/// This method validates the new configuration and applies it to the running bot.
|
/// This method validates the new configuration and applies it to the running bot.
|
||||||
@@ -2591,7 +2586,8 @@ public class TradingBotBase : ITradingBot
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate cooldown end time based on last position closing time
|
// Calculate cooldown end time based on last position closing time
|
||||||
var cooldownEndTime = TradingBox.CalculateCooldownEndTime(LastPositionClosingTime.Value, Config.Timeframe, Config.CooldownPeriod);
|
var cooldownEndTime =
|
||||||
|
TradingBox.CalculateCooldownEndTime(LastPositionClosingTime.Value, Config.Timeframe, Config.CooldownPeriod);
|
||||||
var isInCooldown = (Config.IsForBacktest ? LastCandle.Date : DateTime.UtcNow) < cooldownEndTime;
|
var isInCooldown = (Config.IsForBacktest ? LastCandle.Date : DateTime.UtcNow) < cooldownEndTime;
|
||||||
|
|
||||||
if (isInCooldown)
|
if (isInCooldown)
|
||||||
|
|||||||
Reference in New Issue
Block a user