Orlean (#32)
* 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
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Managing.Domain.Backtests;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Candles;
|
||||
using Managing.Domain.Users;
|
||||
using Orleans;
|
||||
|
||||
namespace Managing.Application.Abstractions.Grains;
|
||||
|
||||
/// <summary>
|
||||
/// Orleans grain interface for Backtest TradingBot operations.
|
||||
/// This interface extends ITradingBotGrain with backtest-specific functionality.
|
||||
/// </summary>
|
||||
public interface IBacktestTradingBotGrain : IGrainWithGuidKey
|
||||
{
|
||||
/// <summary>
|
||||
/// Runs a complete backtest following the exact pattern of GetBacktestingResult from Backtester.cs
|
||||
/// </summary>
|
||||
/// <param name="config">The trading bot configuration for this backtest</param>
|
||||
/// <param name="candles">The candles to use for backtesting</param>
|
||||
/// <param name="user">The user running the backtest (optional, required for saving)</param>
|
||||
/// <param name="save">Whether to save the backtest results</param>
|
||||
/// <param name="withCandles">Whether to include candles and indicators values in the response</param>
|
||||
/// <param name="requestId">The request ID to associate with this backtest</param>
|
||||
/// <param name="metadata">Additional metadata to associate with this backtest</param>
|
||||
/// <returns>The complete backtest result</returns>
|
||||
Task<LightBacktest> RunBacktestAsync(TradingBotConfig config, List<Candle> candles, User user = null, bool save = false, bool withCandles = false, string requestId = null, object metadata = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current backtest progress
|
||||
/// </summary>
|
||||
/// <returns>Backtest progress information</returns>
|
||||
Task<BacktestProgress> GetBacktestProgressAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the progress of a backtest
|
||||
/// </summary>
|
||||
public class BacktestProgress
|
||||
{
|
||||
public bool IsInitialized { get; set; }
|
||||
public int TotalCandles { get; set; }
|
||||
public int ProcessedCandles { get; set; }
|
||||
public double ProgressPercentage { get; set; }
|
||||
public bool IsComplete { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using Managing.Application.Abstractions.Models;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Trades;
|
||||
using Orleans;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.Abstractions.Grains;
|
||||
|
||||
/// <summary>
|
||||
/// Orleans grain interface for TradingBot operations.
|
||||
/// This interface defines the distributed, async operations available for trading bots.
|
||||
/// </summary>
|
||||
public interface ITradingBotGrain : IGrainWithGuidKey
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts the trading bot asynchronously
|
||||
/// </summary>
|
||||
Task StartAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Stops the trading bot asynchronously
|
||||
/// </summary>
|
||||
Task StopAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current status of the trading bot
|
||||
/// </summary>
|
||||
Task<BotStatus> GetStatusAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current configuration of the trading bot
|
||||
/// </summary>
|
||||
Task<TradingBotConfig> GetConfigurationAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Updates the trading bot configuration
|
||||
/// </summary>
|
||||
/// <param name="newConfig">The new configuration to apply</param>
|
||||
/// <returns>True if the configuration was successfully updated</returns>
|
||||
Task<bool> UpdateConfigurationAsync(TradingBotConfig newConfig);
|
||||
|
||||
/// <summary>
|
||||
/// Manually opens a position in the specified direction
|
||||
/// </summary>
|
||||
/// <param name="direction">The direction of the trade (Long/Short)</param>
|
||||
/// <returns>The created Position object</returns>
|
||||
Task<Position> OpenPositionManuallyAsync(TradeDirection direction);
|
||||
|
||||
/// <summary>
|
||||
/// Toggles the bot between watch-only and trading mode
|
||||
/// </summary>
|
||||
Task ToggleIsForWatchOnlyAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets comprehensive bot data including positions, signals, and performance metrics
|
||||
/// </summary>
|
||||
Task<TradingBotResponse> GetBotDataAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Loads a bot backup into the grain state
|
||||
/// </summary>
|
||||
/// <param name="backup">The bot backup to load</param>
|
||||
Task LoadBackupAsync(BotBackup backup);
|
||||
|
||||
/// <summary>
|
||||
/// Forces a backup save of the current bot state
|
||||
/// </summary>
|
||||
Task SaveBackupAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current profit and loss for the bot
|
||||
/// </summary>
|
||||
Task<decimal> GetProfitAndLossAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current win rate percentage for the bot
|
||||
/// </summary>
|
||||
Task<int> GetWinRateAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bot's execution count (number of Run cycles completed)
|
||||
/// </summary>
|
||||
Task<long> GetExecutionCountAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bot's startup time
|
||||
/// </summary>
|
||||
Task<DateTime> GetStartupTimeAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bot's creation date
|
||||
/// </summary>
|
||||
Task<DateTime> GetCreateDateAsync();
|
||||
}
|
||||
Reference in New Issue
Block a user