feat(analyzer): update MQTT handler, active trade monitoring, and dynamic settings
This commit is contained in:
@@ -180,8 +180,8 @@ public class AnalyzerMqttClient : ManagedMqttClient, IHostedService
|
||||
|
||||
if (closedDto != null && !string.IsNullOrWhiteSpace(closedDto.TradeId))
|
||||
{
|
||||
bool isWin = closedDto.Status.Contains("Profit", StringComparison.OrdinalIgnoreCase) ||
|
||||
closedDto.Status.Contains("Win", StringComparison.OrdinalIgnoreCase);
|
||||
bool isWin = closedDto.Status?.Contains("Profit", StringComparison.OrdinalIgnoreCase) == true ||
|
||||
closedDto.Status?.Contains("Win", StringComparison.OrdinalIgnoreCase) == true;
|
||||
|
||||
var feedback = new TradeFeedbackRecord
|
||||
{
|
||||
@@ -252,8 +252,8 @@ public class AnalyzerMqttClient : ManagedMqttClient, IHostedService
|
||||
TriggerType = "Manual",
|
||||
TargetAsset = new TargetAssetInfo
|
||||
{
|
||||
Symbol = manualReq.FundamentalsData?.Ticker ?? manualReq.Symbol.ToUpperInvariant(),
|
||||
Name = manualReq.FundamentalsData?.CompanyName ?? manualReq.Isin.ToUpperInvariant(),
|
||||
Symbol = manualReq.FundamentalsData?.Fundamentals?.Ticker?.Ticker ?? manualReq.FundamentalsData?.Asset?.PrimaryTicker?.Ticker ?? manualReq.Symbol.ToUpperInvariant(),
|
||||
Name = !string.IsNullOrWhiteSpace(manualReq.FundamentalsData?.Asset?.Name) ? manualReq.FundamentalsData.Asset.Name : manualReq.Isin.ToUpperInvariant(),
|
||||
Isin = manualReq.Isin.ToUpperInvariant(),
|
||||
Sector = manualReq.Sector
|
||||
},
|
||||
@@ -308,18 +308,18 @@ public class AnalyzerMqttClient : ManagedMqttClient, IHostedService
|
||||
},
|
||||
FundamentalContext = new FundamentalContextInfo
|
||||
{
|
||||
PeRatio = (double?)manualReq.FundamentalsData?.PeRatioTrailing,
|
||||
ForwardPeRatio = (double?)manualReq.FundamentalsData?.PeRatioForward,
|
||||
PegRatio = (double?)manualReq.FundamentalsData?.PegRatio,
|
||||
MarketCap = (double?)manualReq.FundamentalsData?.MarketCapitalization,
|
||||
DebtToEquity = (double?)manualReq.FundamentalsData?.DebtToEquity,
|
||||
GrossMargin = (double?)manualReq.FundamentalsData?.GrossMargin,
|
||||
NetProfitMargin = (double?)manualReq.FundamentalsData?.NetProfitMargin,
|
||||
ReturnOnEquity = (double?)manualReq.FundamentalsData?.ReturnOnEquity,
|
||||
DividendYield = (double?)manualReq.FundamentalsData?.DividendYield,
|
||||
ShortPercentOfFloat = (double?)manualReq.FundamentalsData?.ShortPercentOfFloat,
|
||||
AnalystTargetMedian = (double?)manualReq.FundamentalsData?.PriceTargetMedian,
|
||||
EvToEbitda = (double?)manualReq.FundamentalsData?.EvToEbitda
|
||||
PeRatio = (double?)manualReq.FundamentalsData?.Fundamentals?.TrailingPe,
|
||||
ForwardPeRatio = (double?)manualReq.FundamentalsData?.Fundamentals?.ForwardPe,
|
||||
PegRatio = (double?)manualReq.FundamentalsData?.Fundamentals?.PegRatio,
|
||||
MarketCap = (double?)manualReq.FundamentalsData?.Fundamentals?.MarketCap,
|
||||
DebtToEquity = (double?)manualReq.FundamentalsData?.Fundamentals?.DebtToEquity,
|
||||
GrossMargin = (double?)manualReq.FundamentalsData?.Fundamentals?.GrossProfit,
|
||||
NetProfitMargin = (double?)manualReq.FundamentalsData?.Fundamentals?.NetIncome,
|
||||
ReturnOnEquity = (double?)manualReq.FundamentalsData?.Fundamentals?.ReturnOnEquity,
|
||||
DividendYield = (double?)manualReq.FundamentalsData?.Fundamentals?.ForwardDividendYield,
|
||||
ShortPercentOfFloat = null,
|
||||
AnalystTargetMedian = null,
|
||||
EvToEbitda = (double?)manualReq.FundamentalsData?.Fundamentals?.EvToEbitda
|
||||
}
|
||||
};
|
||||
|
||||
@@ -346,7 +346,7 @@ public class AnalyzerMqttClient : ManagedMqttClient, IHostedService
|
||||
Sector = manualReq.Sector,
|
||||
Symbol = manualReq.Symbol.ToUpperInvariant(),
|
||||
Isin = manualReq.Isin.ToUpperInvariant(),
|
||||
CompanyName = manualReq.FundamentalsData?.CompanyName ?? manualReq.Symbol,
|
||||
CompanyName = !string.IsNullOrWhiteSpace(manualReq.FundamentalsData?.Asset?.Name) ? manualReq.FundamentalsData.Asset.Name : manualReq.Symbol,
|
||||
EntryPrice = manualReq.CurrentPrice,
|
||||
SignalType = string.Equals(n8nResponse.SuggestedDirection, "Short", StringComparison.OrdinalIgnoreCase) ? "SELL" : "BUY",
|
||||
Status = shouldProceed ? "Proposed" : "Rejected",
|
||||
@@ -427,8 +427,7 @@ public class AnalyzerMqttClient : ManagedMqttClient, IHostedService
|
||||
Status = "ERROR",
|
||||
Message = $"Analysis failed: {ex.Message}"
|
||||
};
|
||||
await PublishAsync($"services/response/analyzer_TriggerManual/{correlationId}",
|
||||
JsonSerializer.Serialize(errorResponse, FinlyticJsonSerializerContext.Default.ManualAnalysisResponseDto));
|
||||
await PublishAsync($"services/response/analyzer_TriggerManual/{correlationId}", errorResponse);
|
||||
}
|
||||
catch (Exception pubEx)
|
||||
{
|
||||
@@ -574,33 +573,38 @@ public class AnalyzerMqttClient : ManagedMqttClient, IHostedService
|
||||
|
||||
if (fundResp != null)
|
||||
{
|
||||
resolvedSymbol = !string.IsNullOrWhiteSpace(fundResp.Ticker) ? fundResp.Ticker : resolvedSymbol;
|
||||
resolvedName = !string.IsNullOrWhiteSpace(fundResp.CompanyName) ? fundResp.CompanyName : resolvedName;
|
||||
string? fundTicker = fundResp.Fundamentals?.Ticker?.Ticker ?? fundResp.Asset?.PrimaryTicker?.Ticker;
|
||||
resolvedSymbol = !string.IsNullOrWhiteSpace(fundTicker) ? fundTicker : resolvedSymbol;
|
||||
resolvedName = !string.IsNullOrWhiteSpace(fundResp.Asset?.Name) ? fundResp.Asset.Name : resolvedName;
|
||||
|
||||
fundInfo = new FundamentalContextInfo
|
||||
{
|
||||
PeRatio = (double?)fundResp.PeRatioTrailing,
|
||||
ForwardPeRatio = (double?)fundResp.PeRatioForward,
|
||||
PegRatio = (double?)fundResp.PegRatio,
|
||||
MarketCap = (double?)fundResp.MarketCapitalization,
|
||||
DebtToEquity = (double?)fundResp.DebtToEquity,
|
||||
GrossMargin = (double?)fundResp.GrossMargin,
|
||||
NetProfitMargin = (double?)fundResp.NetProfitMargin,
|
||||
ReturnOnEquity = (double?)fundResp.ReturnOnEquity,
|
||||
DividendYield = (double?)fundResp.DividendYield,
|
||||
ShortPercentOfFloat = (double?)fundResp.ShortPercentOfFloat,
|
||||
AnalystTargetMedian = (double?)fundResp.PriceTargetMedian,
|
||||
EvToEbitda = (double?)fundResp.EvToEbitda
|
||||
PeRatio = (double?)fundResp.Fundamentals?.TrailingPe,
|
||||
ForwardPeRatio = (double?)fundResp.Fundamentals?.ForwardPe,
|
||||
PegRatio = (double?)fundResp.Fundamentals?.PegRatio,
|
||||
MarketCap = (double?)fundResp.Fundamentals?.MarketCap,
|
||||
DebtToEquity = (double?)fundResp.Fundamentals?.DebtToEquity,
|
||||
GrossMargin = (double?)fundResp.Fundamentals?.GrossProfit,
|
||||
NetProfitMargin = (double?)fundResp.Fundamentals?.NetIncome,
|
||||
ReturnOnEquity = (double?)fundResp.Fundamentals?.ReturnOnEquity,
|
||||
DividendYield = (double?)fundResp.Fundamentals?.ForwardDividendYield,
|
||||
ShortPercentOfFloat = null,
|
||||
AnalystTargetMedian = null,
|
||||
EvToEbitda = (double?)fundResp.Fundamentals?.EvToEbitda
|
||||
};
|
||||
}
|
||||
|
||||
if (sentResp != null)
|
||||
{
|
||||
double compound = sentResp.CurrentSummary?.CompoundScore ?? 0.0;
|
||||
// FinBERT compound score is in range [-1.0, +1.0]. Normalize to [0.0, 1.0] for AI prompt context
|
||||
double normalizedScore = Math.Clamp((compound + 1.0) / 2.0, 0.0, 1.0);
|
||||
|
||||
sentInfo = new SentimentContextInfo
|
||||
{
|
||||
AssetSentimentScore = sentResp.CurrentSummary?.CompoundScore ?? 0.0,
|
||||
SectorSentimentScore = 0.5,
|
||||
NewsSentimentSummary = sentResp.CurrentSummary?.SentimentLabel ?? "Neutral"
|
||||
AssetSentimentScore = Math.Round(normalizedScore, 2),
|
||||
SectorSentimentScore = Math.Round(normalizedScore, 2),
|
||||
NewsSentimentSummary = string.IsNullOrWhiteSpace(sentResp.CurrentSummary?.SentimentLabel) ? "Neutral" : sentResp.CurrentSummary.SentimentLabel
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -684,7 +688,7 @@ public class AnalyzerMqttClient : ManagedMqttClient, IHostedService
|
||||
var supportLevels = new List<double>();
|
||||
var resistanceLevels = new List<double>();
|
||||
|
||||
double currentPrice = (double)(livePriceResp?.CurrentPrice > 0 ? livePriceResp.CurrentPrice : (fundResp?.CurrentPrice > 0 ? fundResp.CurrentPrice : 0.0m));
|
||||
double currentPrice = (double)(livePriceResp?.CurrentPrice > 0 ? livePriceResp.CurrentPrice : 0.0m);
|
||||
if (currentPrice > 0)
|
||||
{
|
||||
supportLevels.Add(Math.Round(currentPrice * 0.98, 2));
|
||||
|
||||
Reference in New Issue
Block a user