75 lines
3.0 KiB
C#
75 lines
3.0 KiB
C#
using System;
|
|
|
|
namespace DesktopBot.Models
|
|
{
|
|
/// <summary>
|
|
/// Rappresenta una singola istanza di bot configurata e associata a un asset.
|
|
/// L'ID univoco viene incorporato nel ClientOrderId di ogni ordine Alpaca,
|
|
/// così le posizioni aperte rimangono associabili al bot anche dopo un riavvio.
|
|
///
|
|
/// Formato ClientOrderId: "BOT_{BotId}_{timestamp}"
|
|
/// Esempio: "BOT_3f2a1b_20250610T143022"
|
|
///
|
|
/// VINCOLO: Ogni bot è strettamente associato a un SINGOLO asset con una SINGOLA strategia.
|
|
/// Una volta assegnato l'asset, il bot viene bloccato (IsAssetLocked=true) e non è più possibile
|
|
/// modificare Symbol, AssetClass o Strategy.
|
|
/// </summary>
|
|
public class BotInstance
|
|
{
|
|
/// <summary>ID univoco del bot (6 hex chars, stabile nel tempo)</summary>
|
|
public string BotId { get; set; } = Guid.NewGuid().ToString("N").Substring(0, 6);
|
|
|
|
/// <summary>Nome leggibile assegnato dall'utente (es. "EMA AAPL #1")</summary>
|
|
public string Name { get; set; } = "Nuovo Bot";
|
|
|
|
/// <summary>Simbolo ticker associato (es. "AAPL", "MSFT")</summary>
|
|
public string Symbol { get; set; } = "";
|
|
|
|
/// <summary>Nome dell'asset completo (es. "Apple Inc.")</summary>
|
|
public string AssetName { get; set; } = "";
|
|
|
|
/// <summary>Classe dell'asset: "us_equity", "crypto", ecc.</summary>
|
|
public string AssetClass { get; set; } = "us_equity";
|
|
|
|
/// <summary>
|
|
/// True quando il bot è stato associato a un asset e la configurazione è bloccata.
|
|
/// Dopo il lock, Symbol, AssetClass e Strategy non possono più essere modificati.
|
|
/// </summary>
|
|
public bool IsAssetLocked { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// Timestamp del momento in cui il bot è stato associato all'asset e bloccato.
|
|
/// Null se il bot non è ancora stato associato a un asset.
|
|
/// </summary>
|
|
public DateTime? LockedAt { get; set; } = null;
|
|
|
|
/// <summary>Bot attivo o sospeso</summary>
|
|
public bool IsEnabled { get; set; } = true;
|
|
|
|
/// <summary>Configurazione della strategia</summary>
|
|
public BotConfiguration Config { get; set; } = new BotConfiguration();
|
|
|
|
/// <summary>Data e ora di creazione del bot</summary>
|
|
public DateTime CreatedAt { get; set; } = DateTime.Now;
|
|
|
|
/// <summary>Note libere dell'utente</summary>
|
|
public string Notes { get; set; } = "";
|
|
|
|
/// <summary>Colore badge nella UI (hex, es. "#00E676")</summary>
|
|
public string BadgeColor { get; set; } = "#00E676";
|
|
|
|
/// <summary>
|
|
/// Blocca il bot associandolo definitivamente all'asset corrente.
|
|
/// Dopo questa operazione, Symbol, AssetClass e Strategy diventano immutabili.
|
|
/// </summary>
|
|
public void LockToAsset()
|
|
{
|
|
if (!IsAssetLocked && !string.IsNullOrWhiteSpace(Symbol))
|
|
{
|
|
IsAssetLocked = true;
|
|
LockedAt = DateTime.Now;
|
|
}
|
|
}
|
|
}
|
|
}
|