Fix backtest
This commit is contained in:
@@ -146,7 +146,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
|
||||
public async Task LoadAccount()
|
||||
{
|
||||
var account = await AccountService.GetAccount(AccountName, false, true);
|
||||
var account = await AccountService.GetAccount(AccountName, false, false);
|
||||
if (account == null)
|
||||
{
|
||||
Logger.LogWarning($"No account found for this {AccountName}");
|
||||
@@ -192,7 +192,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
if (balance < Constants.GMX.Config.MinimumPositionAmount)
|
||||
{
|
||||
await LogWarning(
|
||||
$"Balance on broker is below {Constants.GMX.Config.MinimumPositionAmount} USD (actual: {balance}). Stopping bot and saving backup.");
|
||||
$"Balance on broker is below {Constants.GMX.Config.MinimumPositionAmount} USD (actual: {balance}). Stopping bot {Identifier} and saving backup.");
|
||||
SaveBackup();
|
||||
Stop();
|
||||
return;
|
||||
@@ -587,8 +587,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
lastPrice,
|
||||
signalIdentifier: signal.Identifier);
|
||||
|
||||
var position = await new OpenPositionCommandHandler(ExchangeService, AccountService, TradingService)
|
||||
.Handle(command);
|
||||
var position = (new OpenPositionCommandHandler(ExchangeService, AccountService, TradingService)
|
||||
.Handle(command)).Result;
|
||||
|
||||
if (position != null)
|
||||
{
|
||||
@@ -665,12 +665,11 @@ public class TradingBot : Bot, ITradingBot
|
||||
}
|
||||
else
|
||||
{
|
||||
var command = new ClosePositionCommand(position, lastPrice);
|
||||
var command = new ClosePositionCommand(position, lastPrice, isForBacktest: IsForBacktest);
|
||||
try
|
||||
{
|
||||
var closedPosition =
|
||||
(new ClosePositionCommandHandler(ExchangeService, AccountService, TradingService)
|
||||
.Handle(command)).Result;
|
||||
var closedPosition = (new ClosePositionCommandHandler(ExchangeService, AccountService, TradingService)
|
||||
.Handle(command)).Result;
|
||||
|
||||
if (closedPosition.Status == (PositionStatus.Finished | PositionStatus.Flipped))
|
||||
{
|
||||
@@ -909,7 +908,7 @@ public class TradingBot : Bot, ITradingBot
|
||||
BotTradingBalance = BotTradingBalance,
|
||||
StartupTime = StartupTime,
|
||||
};
|
||||
BotService.SaveOrUpdateBotBackup(Name, BotType, JsonConvert.SerializeObject(data));
|
||||
BotService.SaveOrUpdateBotBackup(User, Identifier, BotType, JsonConvert.SerializeObject(data));
|
||||
}
|
||||
|
||||
public override void LoadBackup(BotBackup backup)
|
||||
@@ -925,6 +924,8 @@ public class TradingBot : Bot, ITradingBot
|
||||
AccountName = data.AccountName;
|
||||
IsForWatchingOnly = data.IsForWatchingOnly;
|
||||
BotTradingBalance = data.BotTradingBalance;
|
||||
Identifier = backup.Identifier;
|
||||
User = backup.User;
|
||||
|
||||
// Restore the startup time if it was previously saved
|
||||
if (data.StartupTime != DateTime.MinValue)
|
||||
|
||||
Reference in New Issue
Block a user