Update healthcheck and display pnl on trades
This commit is contained in:
@@ -347,6 +347,11 @@ public class TradingBot : Bot, ITradingBot
|
||||
if (!IsForBacktest)
|
||||
{
|
||||
position = positionsExchange.FirstOrDefault(p => p.Ticker == Ticker);
|
||||
|
||||
if (position != null)
|
||||
{
|
||||
UpdatePositionPnl(positionForSignal.Identifier, position.ProfitAndLoss.Realized);
|
||||
}
|
||||
}
|
||||
|
||||
if (position.Status == PositionStatus.New)
|
||||
@@ -411,8 +416,6 @@ public class TradingBot : Bot, ITradingBot
|
||||
{
|
||||
Logger.LogInformation(
|
||||
$"Position {signal.Identifier} don't need to be update. Position still opened");
|
||||
|
||||
await SetPositionStatus(signal.Identifier, PositionStatus.Filled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,10 +450,6 @@ public class TradingBot : Bot, ITradingBot
|
||||
{
|
||||
Logger.LogInformation(
|
||||
$"Position {signal.Identifier} don't need to be update. Position still opened");
|
||||
|
||||
position.Status = PositionStatus.Filled;
|
||||
|
||||
await SetPositionStatus(signal.Identifier, PositionStatus.Filled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -468,8 +467,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, ex.Message);
|
||||
//SentrySdk.CaptureException(ex);
|
||||
await LogWarning($"Cannot update position {positionForSignal.Identifier}: {ex.Message}");
|
||||
SentrySdk.CaptureException(ex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -727,6 +726,14 @@ public class TradingBot : Bot, ITradingBot
|
||||
positionStatus == PositionStatus.Filled ? SignalStatus.PositionOpen : SignalStatus.Expired);
|
||||
}
|
||||
|
||||
private void UpdatePositionPnl(string identifier, decimal realized)
|
||||
{
|
||||
Positions.First(p => p.Identifier == identifier).ProfitAndLoss = new ProfitAndLoss()
|
||||
{
|
||||
Realized = realized
|
||||
};
|
||||
}
|
||||
|
||||
private void SetSignalStatus(string signalIdentifier, SignalStatus signalStatus)
|
||||
{
|
||||
if (Signals.Any(s => s.Identifier == signalIdentifier))
|
||||
|
||||
Reference in New Issue
Block a user