@page "/market" @using TradingBot.Models @using TradingBot.Services @using TradingBot.Components.Shared @inject TradingBotService BotService @implements IDisposable @rendermode InteractiveServer Analisi Mercato - TradingBot
@if (selectedConfig != null && currentPrice != null) {
@selectedSymbol.Substring(0, 1)

@selectedConfig.Name

@selectedSymbol
$@currentPrice.Price.ToString("N2")
@Math.Abs(currentPrice.Change24h).ToString("F2")% (24h)
Volume 24h $@currentPrice.Volume24h.ToString("N0")
Holdings @selectedConfig.CurrentHoldings.ToString("F6")
Valore Posizione $@((selectedConfig.CurrentHoldings * currentPrice.Price).ToString("N2"))
@if (currentIndicators != null) {
RSI (14)
@currentIndicators.RSI.ToString("F2")
@GetRSIStatus()
MACD
@currentIndicators.MACD.ToString("F2")
Signal: @currentIndicators.Signal.ToString("F2")
Histogram
@currentIndicators.Histogram.ToString("F4")
@(currentIndicators.Histogram >= 0 ? "Bullish" : "Bearish")
EMA
@currentIndicators.EMA12.ToString("F2")
EMA26: @currentIndicators.EMA26.ToString("F2")
}

Andamento Prezzi

}
@code { [SupplyParameterFromQuery(Name = "symbol")] public string? QuerySymbol { get; set; } private string selectedSymbol = "BTC"; private AssetConfiguration? selectedConfig => BotService.AssetConfigurations.TryGetValue(selectedSymbol, out var c) ? c : null; private MarketPrice? currentPrice => BotService.GetLatestPrice(selectedSymbol); private TechnicalIndicators? currentIndicators; protected override void OnInitialized() { // Set initial symbol from query string if available if (!string.IsNullOrEmpty(QuerySymbol) && BotService.AssetConfigurations.ContainsKey(QuerySymbol)) { selectedSymbol = QuerySymbol; } BotService.OnPriceUpdated += HandlePriceUpdate; BotService.OnIndicatorsUpdated += HandleIndicatorsUpdate; UpdateIndicators(); } protected override void OnParametersSet() { // Update symbol if query parameter changes if (!string.IsNullOrEmpty(QuerySymbol) && QuerySymbol != selectedSymbol && BotService.AssetConfigurations.ContainsKey(QuerySymbol)) { selectedSymbol = QuerySymbol; UpdateIndicators(); } } private void OnAssetChanged() { UpdateIndicators(); StateHasChanged(); } private void UpdateIndicators() { currentIndicators = BotService.GetIndicators(selectedSymbol); } private List? GetPriceList(string symbol) { var history = BotService.GetPriceHistory(symbol); return history?.Select(p => p.Price).ToList(); } private string GetRSIClass() { if (currentIndicators == null) return "neutral"; if (currentIndicators.RSI > 70) return "overbought"; if (currentIndicators.RSI < 30) return "oversold"; return "neutral"; } private string GetRSIStatus() { if (currentIndicators == null) return "Neutral"; if (currentIndicators.RSI > 70) return "Overbought"; if (currentIndicators.RSI < 30) return "Oversold"; return "Neutral"; } private void HandlePriceUpdate(string symbol, MarketPrice price) { if (symbol == selectedSymbol) { InvokeAsync(StateHasChanged); } } private void HandleIndicatorsUpdate(string symbol, TechnicalIndicators indicators) { if (symbol == selectedSymbol) { currentIndicators = indicators; InvokeAsync(StateHasChanged); } } public void Dispose() { BotService.OnPriceUpdated -= HandlePriceUpdate; BotService.OnIndicatorsUpdated -= HandleIndicatorsUpdate; } }