Sviluppo TradingBot
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using DesktopBot.Engine;
|
||||
using DesktopBot.Models;
|
||||
using DesktopBot.Services;
|
||||
|
||||
namespace DesktopBot.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// ViewModel per la configurazione del bot
|
||||
/// </summary>
|
||||
public class BotConfigViewModel : BaseViewModel
|
||||
{
|
||||
private readonly ITradingService _tradingService;
|
||||
private readonly AutomatedBotEngine _botEngine;
|
||||
|
||||
private BotConfiguration _config = new BotConfiguration();
|
||||
private bool _isRunning;
|
||||
private string _statusMessage;
|
||||
|
||||
public BotConfiguration Config
|
||||
{
|
||||
get => _config;
|
||||
set => SetProperty(ref _config, value);
|
||||
}
|
||||
|
||||
public bool IsRunning
|
||||
{
|
||||
get => _isRunning;
|
||||
set => SetProperty(ref _isRunning, value);
|
||||
}
|
||||
|
||||
public string StatusMessage
|
||||
{
|
||||
get => _statusMessage;
|
||||
set => SetProperty(ref _statusMessage, value);
|
||||
}
|
||||
|
||||
public ICommand StartBotCommand { get; }
|
||||
public ICommand StopBotCommand { get; }
|
||||
|
||||
public BotConfigViewModel(ITradingService tradingService, AutomatedBotEngine botEngine)
|
||||
{
|
||||
_tradingService = tradingService;
|
||||
_botEngine = botEngine;
|
||||
|
||||
StartBotCommand = new RelayCommand(
|
||||
async _ => await StartBotAsync(),
|
||||
_ => !IsRunning
|
||||
);
|
||||
|
||||
StopBotCommand = new RelayCommand(
|
||||
_ => StopBot(),
|
||||
_ => IsRunning
|
||||
);
|
||||
}
|
||||
|
||||
public void LoadConfiguration()
|
||||
{
|
||||
Config = new BotConfiguration();
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task StartBotAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
IsRunning = true;
|
||||
StatusMessage = $"Bot avviato - {Config.Symbol} - Strategia: {Config.Strategy}";
|
||||
await _botEngine.StartAsync(Config);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StatusMessage = $"Errore: {ex.Message}";
|
||||
IsRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void StopBot()
|
||||
{
|
||||
_botEngine.Stop();
|
||||
IsRunning = false;
|
||||
StatusMessage = "Bot arrestato";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user