Fix position status when checkbroker say no
This commit is contained in:
@@ -1086,11 +1086,26 @@ public class TradingBotBase : ITradingBot
|
|||||||
|
|
||||||
var reason = $"Cannot open position. There is already a position open for {Config.Ticker} on the broker.";
|
var reason = $"Cannot open position. There is already a position open for {Config.Ticker} on the broker.";
|
||||||
|
|
||||||
if (previousPosition != null && orders.Count >= 2)
|
if (previousPosition != null)
|
||||||
|
{
|
||||||
|
if (orders.Count >= 2)
|
||||||
{
|
{
|
||||||
await SetPositionStatus(previousPosition.SignalIdentifier, PositionStatus.Filled);
|
await SetPositionStatus(previousPosition.SignalIdentifier, PositionStatus.Filled);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// Broker already has an open position, cancel the internally created (DB) position
|
||||||
|
await SetPositionStatus(previousPosition.SignalIdentifier, PositionStatus.Canceled);
|
||||||
|
if (!Config.IsForBacktest)
|
||||||
|
{
|
||||||
|
await UpdatePositionDatabase(previousPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
reason +=
|
||||||
|
" Position open on broker; internal position has been marked as Canceled.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
reason +=
|
reason +=
|
||||||
" Position open on broker but not enough orders or no previous position internally saved by the bot";
|
" Position open on broker but not enough orders or no previous position internally saved by the bot";
|
||||||
|
|||||||
Reference in New Issue
Block a user