get awaiter for openposition command
This commit is contained in:
@@ -344,7 +344,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
var signalForPosition = Signals.FirstOrDefault(s => s.Identifier == position.SignalIdentifier);
|
||||
if (signalForPosition == null)
|
||||
{
|
||||
await LogInformation($"🔍 **Signal Recovery**\nSignal not found for position `{position.Identifier}`\nRecreating signal from position data...");
|
||||
await LogInformation(
|
||||
$"🔍 **Signal Recovery**\nSignal not found for position `{position.Identifier}`\nRecreating signal from position data...");
|
||||
|
||||
// Recreate the signal based on position information
|
||||
signalForPosition = await RecreateSignalFromPosition(position);
|
||||
@@ -454,7 +455,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
try
|
||||
{
|
||||
await ExchangeService.CancelOrder(Account, Config.Ticker);
|
||||
await LogInformation($"✅ **Orders Canceled**\nSuccessfully canceled all orders for: `{Config.Ticker}`");
|
||||
await LogInformation(
|
||||
$"✅ **Orders Canceled**\nSuccessfully canceled all orders for: `{Config.Ticker}`");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -544,7 +546,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
{
|
||||
if (positionForSignal.StopLoss.Price >= lastCandle.Low)
|
||||
{
|
||||
await LogInformation($"🛑 **Stop Loss Hit**\nClosing LONG position\nPrice: `${positionForSignal.StopLoss.Price}`");
|
||||
await LogInformation(
|
||||
$"🛑 **Stop Loss Hit**\nClosing LONG position\nPrice: `${positionForSignal.StopLoss.Price}`");
|
||||
await CloseTrade(signal, positionForSignal, positionForSignal.StopLoss,
|
||||
positionForSignal.StopLoss.Price, true);
|
||||
positionForSignal.StopLoss.SetStatus(TradeStatus.Filled);
|
||||
@@ -552,14 +555,16 @@ public class TradingBot : Bot, ITradingBot
|
||||
else if (positionForSignal.TakeProfit1.Price <= lastCandle.High &&
|
||||
positionForSignal.TakeProfit1.Status != TradeStatus.Filled)
|
||||
{
|
||||
await LogInformation($"🎯 **Take Profit 1 Hit**\nClosing LONG position\nPrice: `${positionForSignal.TakeProfit1.Price}`");
|
||||
await LogInformation(
|
||||
$"🎯 **Take Profit 1 Hit**\nClosing LONG position\nPrice: `${positionForSignal.TakeProfit1.Price}`");
|
||||
await CloseTrade(signal, positionForSignal, positionForSignal.TakeProfit1,
|
||||
positionForSignal.TakeProfit1.Price, positionForSignal.TakeProfit2 == null);
|
||||
positionForSignal.TakeProfit1.SetStatus(TradeStatus.Filled);
|
||||
}
|
||||
else if (positionForSignal.TakeProfit2?.Price <= lastCandle.High)
|
||||
{
|
||||
await LogInformation($"🎯 **Take Profit 2 Hit**\nClosing LONG position\nPrice: `${positionForSignal.TakeProfit2.Price}`");
|
||||
await LogInformation(
|
||||
$"🎯 **Take Profit 2 Hit**\nClosing LONG position\nPrice: `${positionForSignal.TakeProfit2.Price}`");
|
||||
await CloseTrade(signal, positionForSignal, positionForSignal.TakeProfit2,
|
||||
positionForSignal.TakeProfit2.Price, true);
|
||||
positionForSignal.TakeProfit2.SetStatus(TradeStatus.Filled);
|
||||
@@ -569,7 +574,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
{
|
||||
if (positionForSignal.StopLoss.Price <= lastCandle.High)
|
||||
{
|
||||
await LogInformation($"🛑 **Stop Loss Hit**\nClosing SHORT position\nPrice: `${positionForSignal.StopLoss.Price}`");
|
||||
await LogInformation(
|
||||
$"🛑 **Stop Loss Hit**\nClosing SHORT position\nPrice: `${positionForSignal.StopLoss.Price}`");
|
||||
await CloseTrade(signal, positionForSignal, positionForSignal.StopLoss,
|
||||
positionForSignal.StopLoss.Price, true);
|
||||
positionForSignal.StopLoss.SetStatus(TradeStatus.Filled);
|
||||
@@ -577,14 +583,16 @@ public class TradingBot : Bot, ITradingBot
|
||||
else if (positionForSignal.TakeProfit1.Price >= lastCandle.Low &&
|
||||
positionForSignal.TakeProfit1.Status != TradeStatus.Filled)
|
||||
{
|
||||
await LogInformation($"🎯 **Take Profit 1 Hit**\nClosing SHORT position\nPrice: `${positionForSignal.TakeProfit1.Price}`");
|
||||
await LogInformation(
|
||||
$"🎯 **Take Profit 1 Hit**\nClosing SHORT position\nPrice: `${positionForSignal.TakeProfit1.Price}`");
|
||||
await CloseTrade(signal, positionForSignal, positionForSignal.TakeProfit1,
|
||||
positionForSignal.TakeProfit1.Price, positionForSignal.TakeProfit2 == null);
|
||||
positionForSignal.TakeProfit1.SetStatus(TradeStatus.Filled);
|
||||
}
|
||||
else if (positionForSignal.TakeProfit2?.Price >= lastCandle.Low)
|
||||
{
|
||||
await LogInformation($"🎯 **Take Profit 2 Hit**\nClosing SHORT position\nPrice: `${positionForSignal.TakeProfit2.Price}`");
|
||||
await LogInformation(
|
||||
$"🎯 **Take Profit 2 Hit**\nClosing SHORT position\nPrice: `${positionForSignal.TakeProfit2.Price}`");
|
||||
await CloseTrade(signal, positionForSignal, positionForSignal.TakeProfit2,
|
||||
positionForSignal.TakeProfit2.Price, true);
|
||||
positionForSignal.TakeProfit2.SetStatus(TradeStatus.Filled);
|
||||
@@ -706,7 +714,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
signalIdentifier: signal.Identifier);
|
||||
|
||||
var position = (new OpenPositionCommandHandler(ExchangeService, AccountService, TradingService)
|
||||
.Handle(command)).Result;
|
||||
.Handle(command)).GetAwaiter().GetResult();
|
||||
|
||||
if (position != null)
|
||||
{
|
||||
@@ -798,7 +806,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
var lastPosition = recentPositions.First();
|
||||
if (lastPosition.OriginDirection == signal.Direction)
|
||||
{
|
||||
await LogWarning($"🔥 **Loss Streak Limit**\nCannot open position\nMax loss streak: `{Config.MaxLossStreak}` reached\n📉 Last `{recentPositions.Count}` trades were losses\n🎯 Last position: `{lastPosition.OriginDirection}`\nWaiting for opposite direction signal");
|
||||
await LogWarning(
|
||||
$"🔥 **Loss Streak Limit**\nCannot open position\nMax loss streak: `{Config.MaxLossStreak}` reached\n📉 Last `{recentPositions.Count}` trades were losses\n🎯 Last position: `{lastPosition.OriginDirection}`\nWaiting for opposite direction signal");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1011,7 +1020,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
// Subtract fees
|
||||
Config.BotTradingBalance -= GetPositionFees(position);
|
||||
|
||||
Logger.LogInformation($"💰 **Balance Updated**\nNew bot trading balance: `${Config.BotTradingBalance:F2}`");
|
||||
Logger.LogInformation(
|
||||
$"💰 **Balance Updated**\nNew bot trading balance: `${Config.BotTradingBalance:F2}`");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1071,7 +1081,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
if (!position.Status.Equals(positionStatus))
|
||||
{
|
||||
Positions.First(p => p.SignalIdentifier == signalIdentifier).Status = positionStatus;
|
||||
await LogInformation($"📊 **Position Status Change**\nPosition: `{signalIdentifier}`\nStatus: `{position.Status}` → `{positionStatus}`");
|
||||
await LogInformation(
|
||||
$"📊 **Position Status Change**\nPosition: `{signalIdentifier}`\nStatus: `{position.Status}` → `{positionStatus}`");
|
||||
}
|
||||
|
||||
SetSignalStatus(signalIdentifier,
|
||||
@@ -1162,7 +1173,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
public async Task ToggleIsForWatchOnly()
|
||||
{
|
||||
Config.IsForWatchingOnly = !Config.IsForWatchingOnly;
|
||||
await LogInformation($"🔄 **Watch Mode Toggle**\nBot: `{Name}`\nWatch Only: `{(Config.IsForWatchingOnly ? "ON" : "OFF")}`");
|
||||
await LogInformation(
|
||||
$"🔄 **Watch Mode Toggle**\nBot: `{Name}`\nWatch Only: `{(Config.IsForWatchingOnly ? "ON" : "OFF")}`");
|
||||
}
|
||||
|
||||
private async Task LogInformation(string message)
|
||||
@@ -1297,7 +1309,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
throw new Exception("Failed to open position");
|
||||
}
|
||||
|
||||
Logger.LogInformation($"👤 **Manual Position Opened**\nPosition: `{position.Identifier}`\nSignal: `{signal.Identifier}`");
|
||||
Logger.LogInformation(
|
||||
$"👤 **Manual Position Opened**\nPosition: `{position.Identifier}`\nSignal: `{signal.Identifier}`");
|
||||
return position;
|
||||
}
|
||||
|
||||
@@ -1377,7 +1390,9 @@ public class TradingBot : Bot, ITradingBot
|
||||
$"📈 Flip Only in Profit: {(Config.FlipOnlyWhenInProfit ? "✅" : "❌")}\n" +
|
||||
$"⏳ Cooldown: {Config.CooldownPeriod} candles\n" +
|
||||
$"📉 Max Loss Streak: {Config.MaxLossStreak}" +
|
||||
(allowNameChange && newConfig.Name != Config.Name ? $"\n🏷️ Name: {Config.Name} → {newConfig.Name}" : ""));
|
||||
(allowNameChange && newConfig.Name != Config.Name
|
||||
? $"\n🏷️ Name: {Config.Name} → {newConfig.Name}"
|
||||
: ""));
|
||||
|
||||
// Update the configuration
|
||||
Config = newConfig;
|
||||
|
||||
Reference in New Issue
Block a user