* Start building with orlean * Add missing file * Serialize grain state * Remove grain and proxies * update and add plan * Update a bit * Fix backtest grain * Fix backtest grain * Clean a bit
117 lines
2.9 KiB
C#
117 lines
2.9 KiB
C#
using Managing.Domain.Bots;
|
|
using Managing.Domain.Trades;
|
|
using Managing.Domain.Users;
|
|
using static Managing.Common.Enums;
|
|
|
|
namespace Managing.Application.Bots;
|
|
|
|
/// <summary>
|
|
/// Orleans grain state for TradingBot.
|
|
/// This class represents the persistent state of a trading bot grain.
|
|
/// All properties must be serializable for Orleans state management.
|
|
/// </summary>
|
|
[GenerateSerializer]
|
|
public class TradingBotGrainState
|
|
{
|
|
/// <summary>
|
|
/// The trading bot configuration
|
|
/// </summary>
|
|
[Id(0)]
|
|
public TradingBotConfig Config { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// Collection of trading signals generated by the bot
|
|
/// </summary>
|
|
[Id(1)]
|
|
public HashSet<LightSignal> Signals { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// List of trading positions opened by the bot
|
|
/// </summary>
|
|
[Id(2)]
|
|
public List<Position> Positions { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// Historical wallet balances tracked over time
|
|
/// </summary>
|
|
[Id(3)]
|
|
public Dictionary<DateTime, decimal> WalletBalances { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// Current status of the bot (Running, Stopped, etc.)
|
|
/// </summary>
|
|
[Id(4)]
|
|
public BotStatus Status { get; set; } = BotStatus.Down;
|
|
|
|
/// <summary>
|
|
/// When the bot was started
|
|
/// </summary>
|
|
[Id(5)]
|
|
public DateTime StartupTime { get; set; } = DateTime.UtcNow;
|
|
|
|
/// <summary>
|
|
/// When the bot was created
|
|
/// </summary>
|
|
[Id(6)]
|
|
public DateTime CreateDate { get; set; } = DateTime.UtcNow;
|
|
|
|
/// <summary>
|
|
/// The user who owns this bot
|
|
/// </summary>
|
|
[Id(7)]
|
|
public User User { get; set; }
|
|
|
|
/// <summary>
|
|
/// Bot execution counter
|
|
/// </summary>
|
|
[Id(8)]
|
|
public long ExecutionCount { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// Bot identifier/name
|
|
/// </summary>
|
|
[Id(9)]
|
|
public string Identifier { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Bot display name
|
|
/// </summary>
|
|
[Id(10)]
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Preload start date for candles
|
|
/// </summary>
|
|
[Id(11)]
|
|
public DateTime PreloadSince { get; set; } = DateTime.UtcNow;
|
|
|
|
/// <summary>
|
|
/// Number of preloaded candles
|
|
/// </summary>
|
|
[Id(12)]
|
|
public int PreloadedCandlesCount { get; set; } = 0;
|
|
|
|
/// <summary>
|
|
/// Timer interval for bot execution
|
|
/// </summary>
|
|
[Id(13)]
|
|
public int Interval { get; set; } = 60000; // Default 1 minute
|
|
|
|
/// <summary>
|
|
/// Maximum number of signals to keep in memory
|
|
/// </summary>
|
|
[Id(14)]
|
|
public int MaxSignals { get; set; } = 10;
|
|
|
|
/// <summary>
|
|
/// Indicates if the bot has been initialized
|
|
/// </summary>
|
|
[Id(15)]
|
|
public bool IsInitialized { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// Last time the bot state was persisted
|
|
/// </summary>
|
|
[Id(16)]
|
|
public DateTime LastBackupTime { get; set; } = DateTime.UtcNow;
|
|
} |