@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)
{
Volume 24h
$@currentPrice.Volume24h.ToString("N0")
Holdings
@selectedConfig.CurrentHoldings.ToString("F6")
Valore Posizione
$@((selectedConfig.CurrentHoldings * currentPrice.Price).ToString("N2"))
@if (currentIndicators != null)
{
@currentIndicators.RSI.ToString("F2")
@GetRSIStatus()
@currentIndicators.MACD.ToString("F2")
Signal: @currentIndicators.Signal.ToString("F2")
@currentIndicators.Histogram.ToString("F4")
@(currentIndicators.Histogram >= 0 ? "Bullish" : "Bearish")
@currentIndicators.EMA12.ToString("F2")
EMA26: @currentIndicators.EMA26.ToString("F2")
}
}
@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