Add bot worker

This commit is contained in:
2024-06-28 17:26:28 +07:00
parent 7a6d656335
commit d96b2a4c3b
24 changed files with 120 additions and 113 deletions

View File

@@ -23,6 +23,7 @@ public class TradingBot : Bot, ITradingBot
public readonly IMessengerService MessengerService;
public readonly IAccountService AccountService;
private readonly ITradingService TradingService;
private readonly IBotService BotService;
public Account Account { get; set; }
public HashSet<IStrategy> Strategies { get; set; }
@@ -55,6 +56,7 @@ public class TradingBot : Bot, ITradingBot
Timeframe timeframe,
IAccountService accountService,
IMessengerService messengerService,
IBotService botService,
bool isForBacktest = false,
bool isForWatchingOnly = false,
bool flipPosition = false)
@@ -64,7 +66,7 @@ public class TradingBot : Bot, ITradingBot
AccountService = accountService;
MessengerService = messengerService;
TradingService = tradingService;
BotService = botService;
IsForWatchingOnly = isForWatchingOnly;
FlipPosition = flipPosition;
@@ -168,6 +170,9 @@ public class TradingBot : Bot, ITradingBot
if (!IsForWatchingOnly)
await ManagePositions();
if (!IsForBacktest)
SaveBackup();
await UpdateWalletBalances();
Logger.LogInformation($"Candles : {Candles.Count}");
Logger.LogInformation($"Signals : {Signals.Count}");
@@ -659,9 +664,9 @@ public class TradingBot : Bot, ITradingBot
}
}
public override string GetBackup()
public override void SaveBackup()
{
return JsonConvert.SerializeObject(new TradingBotBackup
var data = new TradingBotBackup
{
Name = Name,
BotType = BotType,
@@ -675,7 +680,8 @@ public class TradingBot : Bot, ITradingBot
IsForWatchingOnly = IsForWatchingOnly,
WalletBalances = WalletBalances,
MoneyManagement = MoneyManagement
});
};
BotService.SaveBotBackup(Name, BotType, JsonConvert.SerializeObject(data));
}
public override void LoadBackup(BotBackup backup)