Add user to position + fix few things
This commit is contained in:
@@ -331,7 +331,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
: TradingService.GetPositionByIdentifier(positionForSignal.Identifier);
|
||||
|
||||
var positionsExchange = IsForBacktest
|
||||
? new List<Position>{position}
|
||||
? new List<Position> { position }
|
||||
: await TradingService.GetBrokerPositions(Account);
|
||||
|
||||
if (!IsForBacktest)
|
||||
@@ -344,11 +344,13 @@ public class TradingBot : Bot, ITradingBot
|
||||
var orders = await ExchangeService.GetOpenOrders(Account, Ticker);
|
||||
if (orders.Any())
|
||||
{
|
||||
await LogInformation($"Cannot update Position. Position is still waiting for opening. There is {orders.Count()} open orders.");
|
||||
await LogInformation(
|
||||
$"Cannot update Position. Position is still waiting for opening. There is {orders.Count()} open orders.");
|
||||
}
|
||||
else
|
||||
{
|
||||
await LogWarning($"Cannot update Position. No position on exchange and no orders. Position {signal.Identifier} might be closed already.");
|
||||
await LogWarning(
|
||||
$"Cannot update Position. No position on exchange and no orders. Position {signal.Identifier} might be closed already.");
|
||||
await HandleClosedPosition(positionForSignal);
|
||||
}
|
||||
}
|
||||
@@ -446,7 +448,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
Logger.LogInformation($"Try to re-open position");
|
||||
await OpenPosition(signal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -525,15 +527,16 @@ public class TradingBot : Bot, ITradingBot
|
||||
Ticker,
|
||||
IsForBacktest ? PositionInitiator.PaperTrading : PositionInitiator.Bot,
|
||||
signal.Date,
|
||||
User,
|
||||
IsForBacktest,
|
||||
lastPrice,
|
||||
balance: WalletBalances.LastOrDefault().Value,
|
||||
fee: Fee);
|
||||
fee: Fee,
|
||||
signalIdentifier: signal.Identifier);
|
||||
|
||||
var position = await new OpenPositionCommandHandler(ExchangeService, AccountService, TradingService)
|
||||
.Handle(command);
|
||||
|
||||
|
||||
if (position != null)
|
||||
{
|
||||
position.SignalIdentifier = signal.Identifier;
|
||||
@@ -691,7 +694,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
await ExchangeService.CancelOrder(Account, Ticker);
|
||||
var closePendingOrderStatus = await ExchangeService.CancelOrder(Account, Ticker);
|
||||
Logger.LogInformation($"Closing all {Ticker} orders status : {closePendingOrderStatus}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -839,7 +842,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
|
||||
// Create a fake signal for manual position opening
|
||||
var signal = new Signal(Ticker, direction, Confidence.Low, lastCandle, lastCandle.Date, TradingExchanges.GmxV2,
|
||||
StrategyType.Stc, SignalType.Signal);
|
||||
StrategyType.Stc, SignalType.Signal);
|
||||
signal.Status = SignalStatus.WaitingForPosition; // Ensure status is correct
|
||||
signal.User = Account.User; // Assign user
|
||||
|
||||
@@ -854,7 +857,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
if (position == null)
|
||||
{
|
||||
// Clean up the signal if position creation failed
|
||||
SetSignalStatus(signal.Identifier, SignalStatus.Expired);
|
||||
SetSignalStatus(signal.Identifier, SignalStatus.Expired);
|
||||
throw new Exception("Failed to open position");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user