Update status to match UI
This commit is contained in:
@@ -297,7 +297,7 @@ public class BotController : BaseController
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<List<TradingBotResponse>> GetActiveBots()
|
public async Task<List<TradingBotResponse>> GetActiveBots()
|
||||||
{
|
{
|
||||||
return await GetBotsByStatusAsync(BotStatus.Up);
|
return await GetBotsByStatusAsync(BotStatus.Running);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -328,7 +328,7 @@ public class BotController : BaseController
|
|||||||
return new List<TradingBotResponse>();
|
return new List<TradingBotResponse>();
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = await _mediator.Send(new GetBotsByUserAndStatusCommand(user.Id, BotStatus.None));
|
var result = await _mediator.Send(new GetBotsByUserAndStatusCommand(user.Id, BotStatus.Saved));
|
||||||
return MapBotsToTradingBotResponse(result);
|
return MapBotsToTradingBotResponse(result);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -467,7 +467,7 @@ public class BotController : BaseController
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task NotifyBotSubscriberAsync()
|
private async Task NotifyBotSubscriberAsync()
|
||||||
{
|
{
|
||||||
var botsList = await GetBotsByStatusAsync(BotStatus.Up);
|
var botsList = await GetBotsByStatusAsync(BotStatus.Running);
|
||||||
await _hubContext.Clients.All.SendAsync("BotsSubscription", botsList);
|
await _hubContext.Clients.All.SendAsync("BotsSubscription", botsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,7 +495,7 @@ public class BotController : BaseController
|
|||||||
return NotFound($"Bot with identifier {request.Identifier} not found or is not a trading bot");
|
return NotFound($"Bot with identifier {request.Identifier} not found or is not a trading bot");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bot.Status != BotStatus.Up)
|
if (bot.Status != BotStatus.Running)
|
||||||
{
|
{
|
||||||
return BadRequest($"Bot with identifier {request.Identifier} is not running");
|
return BadRequest($"Bot with identifier {request.Identifier} is not running");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ public class DataController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get active bots
|
// Get active bots
|
||||||
var activeBots = await _mediator.Send(new GetBotsByStatusCommand(BotStatus.Up));
|
var activeBots = await _mediator.Send(new GetBotsByStatusCommand(BotStatus.Running));
|
||||||
var currentCount = activeBots.Count();
|
var currentCount = activeBots.Count();
|
||||||
|
|
||||||
// Get previous count from cache
|
// Get previous count from cache
|
||||||
@@ -345,7 +345,7 @@ public class DataController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get active bots
|
// Get active bots
|
||||||
var activeBots = await _mediator.Send(new GetBotsByStatusCommand(BotStatus.Up));
|
var activeBots = await _mediator.Send(new GetBotsByStatusCommand(BotStatus.Running));
|
||||||
|
|
||||||
// Calculate PnL for each bot once and store in a list of tuples
|
// Calculate PnL for each bot once and store in a list of tuples
|
||||||
var botsWithPnL = activeBots
|
var botsWithPnL = activeBots
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class BotRegistryEntry
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public BotRegistryEntry(Guid identifier, int userId, BotStatus status = BotStatus.None)
|
public BotRegistryEntry(Guid identifier, int userId, BotStatus status = BotStatus.Saved)
|
||||||
{
|
{
|
||||||
Identifier = identifier;
|
Identifier = identifier;
|
||||||
UserId = userId;
|
UserId = userId;
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class AgentGrain : Grain, IAgentGrain, IRemindable
|
|||||||
Losses = totalLosses,
|
Losses = totalLosses,
|
||||||
TotalROI = totalROI,
|
TotalROI = totalROI,
|
||||||
Runtime = runtime,
|
Runtime = runtime,
|
||||||
ActiveStrategiesCount = bots.Count(b => b.Status == BotStatus.Up),
|
ActiveStrategiesCount = bots.Count(b => b.Status == BotStatus.Running),
|
||||||
TotalVolume = totalVolume,
|
TotalVolume = totalVolume,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
|
|||||||
|
|
||||||
// O(1) FIX: Decrement the counters based on the removed entry's status
|
// O(1) FIX: Decrement the counters based on the removed entry's status
|
||||||
_state.State.TotalBotsCount--;
|
_state.State.TotalBotsCount--;
|
||||||
if (entryToRemove.Status == BotStatus.Up)
|
if (entryToRemove.Status == BotStatus.Running)
|
||||||
{
|
{
|
||||||
_state.State.ActiveBotsCount--;
|
_state.State.ActiveBotsCount--;
|
||||||
}
|
}
|
||||||
@@ -140,11 +140,11 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
|
|||||||
}
|
}
|
||||||
|
|
||||||
// O(1) FIX: Conditionally adjust the counter
|
// O(1) FIX: Conditionally adjust the counter
|
||||||
if (newStatus == BotStatus.Up && previousStatus != BotStatus.Up)
|
if (newStatus == BotStatus.Running && previousStatus != BotStatus.Running)
|
||||||
{
|
{
|
||||||
_state.State.ActiveBotsCount++;
|
_state.State.ActiveBotsCount++;
|
||||||
}
|
}
|
||||||
else if (newStatus != BotStatus.Up && previousStatus == BotStatus.Up)
|
else if (newStatus != BotStatus.Running && previousStatus == BotStatus.Running)
|
||||||
{
|
{
|
||||||
_state.State.ActiveBotsCount--;
|
_state.State.ActiveBotsCount--;
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,7 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
|
|||||||
if (!_state.State.Bots.TryGetValue(identifier, out var entry))
|
if (!_state.State.Bots.TryGetValue(identifier, out var entry))
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Bot {Identifier} is not registered in the registry, returning None", identifier);
|
_logger.LogWarning("Bot {Identifier} is not registered in the registry, returning None", identifier);
|
||||||
return Task.FromResult(BotStatus.None);
|
return Task.FromResult(BotStatus.Saved);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(entry.Status);
|
return Task.FromResult(entry.Status);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
|||||||
var agentGrain = GrainFactory.GetGrain<IAgentGrain>(user.Id);
|
var agentGrain = GrainFactory.GetGrain<IAgentGrain>(user.Id);
|
||||||
await agentGrain.RegisterBotAsync(_state.State.Identifier);
|
await agentGrain.RegisterBotAsync(_state.State.Identifier);
|
||||||
|
|
||||||
await SaveBotAsync(BotStatus.None);
|
await SaveBotAsync(BotStatus.Saved);
|
||||||
|
|
||||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} created successfully", this.GetPrimaryKey());
|
_logger.LogInformation("LiveTradingBotGrain {GrainId} created successfully", this.GetPrimaryKey());
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
|||||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} activated. Registry status: {Status}",
|
_logger.LogInformation("LiveTradingBotGrain {GrainId} activated. Registry status: {Status}",
|
||||||
botId, botStatus);
|
botId, botStatus);
|
||||||
|
|
||||||
if (botStatus == BotStatus.Up && _tradingBot == null)
|
if (botStatus == BotStatus.Running && _tradingBot == null)
|
||||||
{
|
{
|
||||||
// Now, we can proceed with resuming the bot.
|
// Now, we can proceed with resuming the bot.
|
||||||
await ResumeBotInternalAsync();
|
await ResumeBotInternalAsync();
|
||||||
@@ -124,8 +124,8 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
|||||||
await RegisterReminder();
|
await RegisterReminder();
|
||||||
|
|
||||||
// Update both database and registry status
|
// Update both database and registry status
|
||||||
await SaveBotAsync(BotStatus.Up);
|
await SaveBotAsync(BotStatus.Running);
|
||||||
await UpdateBotRegistryStatus(BotStatus.Up);
|
await UpdateBotRegistryStatus(BotStatus.Running);
|
||||||
|
|
||||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} resumed successfully", this.GetPrimaryKey());
|
_logger.LogInformation("LiveTradingBotGrain {GrainId} resumed successfully", this.GetPrimaryKey());
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "Failed to resume bot {GrainId}", this.GetPrimaryKey());
|
_logger.LogError(ex, "Failed to resume bot {GrainId}", this.GetPrimaryKey());
|
||||||
_tradingBot = null; // Clean up on failure
|
_tradingBot = null; // Clean up on failure
|
||||||
await UpdateBotRegistryStatus(BotStatus.Down);
|
await UpdateBotRegistryStatus(BotStatus.Stopped);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
|||||||
var status = await botRegistry.GetBotStatus(botId);
|
var status = await botRegistry.GetBotStatus(botId);
|
||||||
|
|
||||||
// Check if already running
|
// Check if already running
|
||||||
if (status == BotStatus.Up && _tradingBot != null)
|
if (status == BotStatus.Running && _tradingBot != null)
|
||||||
{
|
{
|
||||||
await RegisterReminder();
|
await RegisterReminder();
|
||||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} is already running", this.GetPrimaryKey());
|
_logger.LogInformation("LiveTradingBotGrain {GrainId} is already running", this.GetPrimaryKey());
|
||||||
@@ -162,7 +162,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "Failed to start LiveTradingBotGrain {GrainId}", this.GetPrimaryKey());
|
_logger.LogError(ex, "Failed to start LiveTradingBotGrain {GrainId}", this.GetPrimaryKey());
|
||||||
// Ensure registry status is correct on failure
|
// Ensure registry status is correct on failure
|
||||||
await UpdateBotRegistryStatus(BotStatus.Down);
|
await UpdateBotRegistryStatus(BotStatus.Stopped);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
|||||||
// The check is now against the registry status
|
// The check is now against the registry status
|
||||||
var botRegistry = GrainFactory.GetGrain<ILiveBotRegistryGrain>(0);
|
var botRegistry = GrainFactory.GetGrain<ILiveBotRegistryGrain>(0);
|
||||||
var botStatus = await botRegistry.GetBotStatus(this.GetPrimaryKey());
|
var botStatus = await botRegistry.GetBotStatus(this.GetPrimaryKey());
|
||||||
if (botStatus == BotStatus.Down)
|
if (botStatus == BotStatus.Stopped)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Bot {GrainId} is already stopped", this.GetPrimaryKey());
|
_logger.LogInformation("Bot {GrainId} is already stopped", this.GetPrimaryKey());
|
||||||
return;
|
return;
|
||||||
@@ -211,10 +211,10 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
|||||||
// Sync state from the volatile TradingBotBase before destroying it
|
// Sync state from the volatile TradingBotBase before destroying it
|
||||||
SyncStateFromBase();
|
SyncStateFromBase();
|
||||||
await _state.WriteStateAsync();
|
await _state.WriteStateAsync();
|
||||||
await SaveBotAsync(BotStatus.Down);
|
await SaveBotAsync(BotStatus.Stopped);
|
||||||
_tradingBot = null;
|
_tradingBot = null;
|
||||||
|
|
||||||
await UpdateBotRegistryStatus(BotStatus.Down);
|
await UpdateBotRegistryStatus(BotStatus.Stopped);
|
||||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} stopped successfully", this.GetPrimaryKey());
|
_logger.LogInformation("LiveTradingBotGrain {GrainId} stopped successfully", this.GetPrimaryKey());
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -297,7 +297,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
|||||||
await _state.WriteStateAsync();
|
await _state.WriteStateAsync();
|
||||||
|
|
||||||
// Save bot statistics to database
|
// Save bot statistics to database
|
||||||
await SaveBotAsync(BotStatus.Up);
|
await SaveBotAsync(BotStatus.Running);
|
||||||
}
|
}
|
||||||
catch (ObjectDisposedException)
|
catch (ObjectDisposedException)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,12 +52,12 @@ namespace Managing.Application.ManageBot
|
|||||||
{
|
{
|
||||||
var grain = _grainFactory.GetGrain<ILiveTradingBotGrain>(identifier);
|
var grain = _grainFactory.GetGrain<ILiveTradingBotGrain>(identifier);
|
||||||
await grain.StopAsync();
|
await grain.StopAsync();
|
||||||
return BotStatus.Down;
|
return BotStatus.Stopped;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_tradingBotLogger.LogError(e, "Error stopping bot {Identifier}", identifier);
|
_tradingBotLogger.LogError(e, "Error stopping bot {Identifier}", identifier);
|
||||||
return BotStatus.Down;
|
return BotStatus.Stopped;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,13 +97,13 @@ namespace Managing.Application.ManageBot
|
|||||||
var previousStatus = await registryGrain.GetBotStatus(identifier);
|
var previousStatus = await registryGrain.GetBotStatus(identifier);
|
||||||
|
|
||||||
// If bot is already up, return the status directly
|
// If bot is already up, return the status directly
|
||||||
if (previousStatus == BotStatus.Up)
|
if (previousStatus == BotStatus.Running)
|
||||||
{
|
{
|
||||||
return BotStatus.Up;
|
return BotStatus.Running;
|
||||||
}
|
}
|
||||||
|
|
||||||
var botGrain = _grainFactory.GetGrain<ILiveTradingBotGrain>(identifier);
|
var botGrain = _grainFactory.GetGrain<ILiveTradingBotGrain>(identifier);
|
||||||
if (previousStatus == BotStatus.None)
|
if (previousStatus == BotStatus.Saved)
|
||||||
{
|
{
|
||||||
// First time startup
|
// First time startup
|
||||||
await botGrain.StartAsync();
|
await botGrain.StartAsync();
|
||||||
@@ -134,12 +134,12 @@ namespace Managing.Application.ManageBot
|
|||||||
await _messengerService.SendTradeMessage(restartMessage, false, account.User);
|
await _messengerService.SendTradeMessage(restartMessage, false, account.User);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BotStatus.Up;
|
return BotStatus.Running;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_tradingBotLogger.LogError(e, "Error restarting bot {Identifier}", identifier);
|
_tradingBotLogger.LogError(e, "Error restarting bot {Identifier}", identifier);
|
||||||
return BotStatus.Down;
|
return BotStatus.Stopped;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ namespace Managing.Application.ManageBot
|
|||||||
|
|
||||||
public async Task<IEnumerable<string>> GetActiveBotsNamesAsync()
|
public async Task<IEnumerable<string>> GetActiveBotsNamesAsync()
|
||||||
{
|
{
|
||||||
var bots = await _botRepository.GetBotsByStatusAsync(BotStatus.Up);
|
var bots = await _botRepository.GetBotsByStatusAsync(BotStatus.Running);
|
||||||
return bots.Select(b => b.Name);
|
return bots.Select(b => b.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace Managing.Application.ManageBot
|
|||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var result = new List<AgentStatusResponse>();
|
var result = new List<AgentStatusResponse>();
|
||||||
var allActiveBots = await _botService.GetBotsByStatusAsync(BotStatus.Up);
|
var allActiveBots = await _botService.GetBotsByStatusAsync(BotStatus.Running);
|
||||||
|
|
||||||
// Group bots by user and determine status
|
// Group bots by user and determine status
|
||||||
var agentGroups = allActiveBots
|
var agentGroups = allActiveBots
|
||||||
@@ -38,7 +38,7 @@ namespace Managing.Application.ManageBot
|
|||||||
var bots = agentGroup.ToList();
|
var bots = agentGroup.ToList();
|
||||||
|
|
||||||
// Determine agent status: Online if at least one strategy is running, Offline otherwise
|
// Determine agent status: Online if at least one strategy is running, Offline otherwise
|
||||||
var agentStatus = bots.Any(bot => bot.Status == BotStatus.Up)
|
var agentStatus = bots.Any(bot => bot.Status == BotStatus.Running)
|
||||||
? AgentStatus.Online
|
? AgentStatus.Online
|
||||||
: AgentStatus.Offline;
|
: AgentStatus.Offline;
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace Managing.Application.ManageBot
|
|||||||
throw new Exception($"Failed to start bot: {ex.Message}, {ex.StackTrace}");
|
throw new Exception($"Failed to start bot: {ex.Message}, {ex.StackTrace}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return request.CreateOnly ? BotStatus.None : BotStatus.Up;
|
return request.CreateOnly ? BotStatus.Saved : BotStatus.Running;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ namespace Managing.Application.ManageBot
|
|||||||
var userBots = await _botService.GetBotsByUser(request.User.Id);
|
var userBots = await _botService.GetBotsByUser(request.User.Id);
|
||||||
|
|
||||||
// Filter only active bots (status Up)
|
// Filter only active bots (status Up)
|
||||||
var activeBots = userBots.Where(bot => bot.Status == BotStatus.Up).ToList();
|
var activeBots = userBots.Where(bot => bot.Status == BotStatus.Running).ToList();
|
||||||
|
|
||||||
if (!activeBots.Any())
|
if (!activeBots.Any())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class BalanceTrackingWorker : BaseWorker<BalanceTrackingWorker>
|
|||||||
_logger.LogInformation("Starting balance tracking...");
|
_logger.LogInformation("Starting balance tracking...");
|
||||||
|
|
||||||
// Get all active bots
|
// Get all active bots
|
||||||
var bots = await _mediator.Send(new GetBotsByStatusCommand(BotStatus.Up));
|
var bots = await _mediator.Send(new GetBotsByStatusCommand(BotStatus.Running));
|
||||||
|
|
||||||
var botCount = bots.Count();
|
var botCount = bots.Count();
|
||||||
if (botCount == 0)
|
if (botCount == 0)
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ public static class Enums
|
|||||||
|
|
||||||
public enum BotStatus
|
public enum BotStatus
|
||||||
{
|
{
|
||||||
None,
|
Saved,
|
||||||
Down,
|
Stopped,
|
||||||
Up,
|
Running,
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SignalStatus
|
public enum SignalStatus
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ public class AgentSummaryRepository : IAgentSummaryRepository
|
|||||||
{
|
{
|
||||||
var agentSummaries = await _context.AgentSummaries
|
var agentSummaries = await _context.AgentSummaries
|
||||||
.Include(a => a.User)
|
.Include(a => a.User)
|
||||||
.Where(a => _context.Bots.Any(b => b.UserId == a.UserId && b.Status == BotStatus.Up))
|
.Where(a => _context.Bots.Any(b => b.UserId == a.UserId && b.Status == BotStatus.Running))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
return agentSummaries.Select(MapToDomain);
|
return agentSummaries.Select(MapToDomain);
|
||||||
|
|||||||
@@ -1239,6 +1239,41 @@ export class BotClient extends AuthorizedApiBase {
|
|||||||
return Promise.resolve<BotStatus>(null as any);
|
return Promise.resolve<BotStatus>(null as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bot_StopAll(): Promise<boolean> {
|
||||||
|
let url_ = this.baseUrl + "/Bot/StopAll";
|
||||||
|
url_ = url_.replace(/[?&]$/, "");
|
||||||
|
|
||||||
|
let options_: RequestInit = {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.transformOptions(options_).then(transformedOptions_ => {
|
||||||
|
return this.http.fetch(url_, transformedOptions_);
|
||||||
|
}).then((_response: Response) => {
|
||||||
|
return this.processBot_StopAll(_response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected processBot_StopAll(response: Response): Promise<boolean> {
|
||||||
|
const status = response.status;
|
||||||
|
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||||
|
if (status === 200) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
let result200: any = null;
|
||||||
|
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as boolean;
|
||||||
|
return result200;
|
||||||
|
});
|
||||||
|
} else if (status !== 200 && status !== 204) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Promise.resolve<boolean>(null as any);
|
||||||
|
}
|
||||||
|
|
||||||
bot_Delete(identifier: string | undefined): Promise<boolean> {
|
bot_Delete(identifier: string | undefined): Promise<boolean> {
|
||||||
let url_ = this.baseUrl + "/Bot/Delete?";
|
let url_ = this.baseUrl + "/Bot/Delete?";
|
||||||
if (identifier === null)
|
if (identifier === null)
|
||||||
@@ -4308,9 +4343,9 @@ export interface SaveBotRequest extends StartBotRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum BotStatus {
|
export enum BotStatus {
|
||||||
None = "None",
|
Saved = "Saved",
|
||||||
Down = "Down",
|
Stopped = "Stopped",
|
||||||
Up = "Up",
|
Running = "Running",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TradingBotResponse {
|
export interface TradingBotResponse {
|
||||||
@@ -4523,7 +4558,7 @@ export interface StrategyPerformance {
|
|||||||
|
|
||||||
export interface UserStrategyDetailsViewModel {
|
export interface UserStrategyDetailsViewModel {
|
||||||
name?: string | null;
|
name?: string | null;
|
||||||
state?: string | null;
|
state?: BotStatus;
|
||||||
pnL?: number;
|
pnL?: number;
|
||||||
roiPercentage?: number;
|
roiPercentage?: number;
|
||||||
roiLast24H?: number;
|
roiLast24H?: number;
|
||||||
@@ -4533,8 +4568,8 @@ export interface UserStrategyDetailsViewModel {
|
|||||||
volumeLast24H?: number;
|
volumeLast24H?: number;
|
||||||
wins?: number;
|
wins?: number;
|
||||||
losses?: number;
|
losses?: number;
|
||||||
positions?: { [key: string]: Position; } | null;
|
positions?: Position[] | null;
|
||||||
identifier?: string | null;
|
identifier?: string;
|
||||||
walletBalances?: { [key: string]: number; } | null;
|
walletBalances?: { [key: string]: number; } | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -731,9 +731,9 @@ export interface SaveBotRequest extends StartBotRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum BotStatus {
|
export enum BotStatus {
|
||||||
None = "None",
|
Saved = "Saved",
|
||||||
Down = "Down",
|
Stopped = "Stopped",
|
||||||
Up = "Up",
|
Running = "Running",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TradingBotResponse {
|
export interface TradingBotResponse {
|
||||||
@@ -946,7 +946,7 @@ export interface StrategyPerformance {
|
|||||||
|
|
||||||
export interface UserStrategyDetailsViewModel {
|
export interface UserStrategyDetailsViewModel {
|
||||||
name?: string | null;
|
name?: string | null;
|
||||||
state?: string | null;
|
state?: BotStatus;
|
||||||
pnL?: number;
|
pnL?: number;
|
||||||
roiPercentage?: number;
|
roiPercentage?: number;
|
||||||
roiLast24H?: number;
|
roiLast24H?: number;
|
||||||
@@ -956,8 +956,8 @@ export interface UserStrategyDetailsViewModel {
|
|||||||
volumeLast24H?: number;
|
volumeLast24H?: number;
|
||||||
wins?: number;
|
wins?: number;
|
||||||
losses?: number;
|
losses?: number;
|
||||||
positions?: { [key: string]: Position; } | null;
|
positions?: Position[] | null;
|
||||||
identifier?: string | null;
|
identifier?: string;
|
||||||
walletBalances?: { [key: string]: number; } | null;
|
walletBalances?: { [key: string]: number; } | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ type UseBotsProps = {
|
|||||||
callback?: (data: TradingBotResponse[]) => void | undefined
|
callback?: (data: TradingBotResponse[]) => void | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const useBots = ({status = BotStatus.None, callback}: UseBotsProps) => {
|
const useBots = ({status = BotStatus.Saved, callback}: UseBotsProps) => {
|
||||||
const {apiUrl} = useApiUrlStore()
|
const {apiUrl} = useApiUrlStore()
|
||||||
const botClient = new BotClient({}, apiUrl)
|
const botClient = new BotClient({}, apiUrl)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import TradesModal from '../../components/mollecules/TradesModal/TradesModal'
|
|||||||
import {TradeChart, UnifiedTradingModal} from '../../components/organism'
|
import {TradeChart, UnifiedTradingModal} from '../../components/organism'
|
||||||
import {
|
import {
|
||||||
BotClient,
|
BotClient,
|
||||||
|
BotStatus,
|
||||||
MoneyManagement,
|
MoneyManagement,
|
||||||
Position,
|
Position,
|
||||||
TradingBotConfig,
|
TradingBotConfig,
|
||||||
@@ -28,9 +29,23 @@ function baseBadgeClass(isOutlined = false) {
|
|||||||
return classes
|
return classes
|
||||||
}
|
}
|
||||||
|
|
||||||
function cardClasses(botStatus: string) {
|
function cardClasses(botStatus: BotStatus) {
|
||||||
const classes =
|
let classes = 'card bg-base-300 shadow-md '
|
||||||
'card bg-base-300 shadow-md ' + (botStatus == 'Up' ? 'shadow-success' : '')
|
|
||||||
|
switch (botStatus) {
|
||||||
|
case BotStatus.Running:
|
||||||
|
classes += 'shadow-success'
|
||||||
|
break
|
||||||
|
case BotStatus.Saved:
|
||||||
|
classes += 'shadow-info'
|
||||||
|
break
|
||||||
|
case BotStatus.Stopped:
|
||||||
|
classes += 'shadow-warning'
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
// No additional shadow for other statuses
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
return classes
|
return classes
|
||||||
}
|
}
|
||||||
@@ -154,7 +169,6 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
|||||||
const isUp = status == 'Up'
|
const isUp = status == 'Up'
|
||||||
const t = new Toast(isUp ? 'Stoping bot' : 'Restarting bot')
|
const t = new Toast(isUp ? 'Stoping bot' : 'Restarting bot')
|
||||||
|
|
||||||
console.log('toggleBotStatus', status, identifier)
|
|
||||||
if (status == 'Up') {
|
if (status == 'Up') {
|
||||||
client
|
client
|
||||||
.bot_Stop(identifier)
|
.bot_Stop(identifier)
|
||||||
@@ -224,7 +238,7 @@ const BotList: React.FC<IBotList> = ({ list }) => {
|
|||||||
key={index.toString()}
|
key={index.toString()}
|
||||||
className="sm:w-1 md:w-1/2 xl:w-1/2 w-full p-2"
|
className="sm:w-1 md:w-1/2 xl:w-1/2 w-full p-2"
|
||||||
>
|
>
|
||||||
<div className={cardClasses(bot.status)}>
|
<div className={cardClasses(bot.status as BotStatus)}>
|
||||||
<figure className="w-full">
|
<figure className="w-full">
|
||||||
{bot.candles && bot.candles.length > 0 ? (
|
{bot.candles && bot.candles.length > 0 ? (
|
||||||
<TradeChart
|
<TradeChart
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ const Bots: React.FC = () => {
|
|||||||
queryFn: () => {
|
queryFn: () => {
|
||||||
switch (activeTab) {
|
switch (activeTab) {
|
||||||
case 0: // All Active Bots
|
case 0: // All Active Bots
|
||||||
return botClient.bot_GetBotsPaginated(pageNumber, pageSize, BotStatus.Up, undefined, undefined, undefined, 'CreatedAt', 'Desc')
|
return botClient.bot_GetBotsPaginated(pageNumber, pageSize, BotStatus.Running, undefined, undefined, undefined, 'CreatedAt', 'Desc')
|
||||||
case 1: // My Active Bots
|
case 1: // My Active Bots
|
||||||
return botClient.bot_GetBotsPaginated(pageNumber, pageSize, BotStatus.Up, undefined, undefined, currentUser?.agentName, 'CreatedAt', 'Desc')
|
return botClient.bot_GetBotsPaginated(pageNumber, pageSize, BotStatus.Running, undefined, undefined, currentUser?.agentName, 'CreatedAt', 'Desc')
|
||||||
case 2: // My Down Bots
|
case 2: // My Down Bots
|
||||||
return botClient.bot_GetBotsPaginated(pageNumber, pageSize, BotStatus.Down, undefined, undefined, currentUser?.agentName, 'CreatedAt', 'Desc')
|
return botClient.bot_GetBotsPaginated(pageNumber, pageSize, BotStatus.Stopped, undefined, undefined, currentUser?.agentName, 'CreatedAt', 'Desc')
|
||||||
case 3: // Saved Bots
|
case 3: // Saved Bots
|
||||||
return botClient.bot_GetBotsPaginated(pageNumber, pageSize, BotStatus.None, undefined, undefined, currentUser?.agentName, 'CreatedAt', 'Desc')
|
return botClient.bot_GetBotsPaginated(pageNumber, pageSize, BotStatus.Saved, undefined, undefined, currentUser?.agentName, 'CreatedAt', 'Desc')
|
||||||
default:
|
default:
|
||||||
return botClient.bot_GetBotsPaginated(pageNumber, pageSize, undefined, undefined, undefined, undefined, 'CreatedAt', 'Desc')
|
return botClient.bot_GetBotsPaginated(pageNumber, pageSize, undefined, undefined, undefined, undefined, 'CreatedAt', 'Desc')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user