private void PublishSentiment(IDictionary <string, TrackingResult[]> retrieve, string type) { log.LogInformation("Retrieving sentiment {0}...", type); if (retrieve == null || retrieve.Count == 0) { log.LogWarning("Nothing to process - {0}", type); return; } var messages = new List <string>(); foreach (var stock in retrieve) { if (stock.Value != null) { foreach (var record in stock.Value) { if (record.TotalMessages > 0) { messages.Add($"{record.GetEmoji()} {stock.Key}: {record.Average:F2}({record.TotalMessages})"); } } } else { log.LogWarning("Not found sentiment for {0}", stock); } } var message = new MultiItemMessage($"Average sentiment ({type}):", messages.ToArray()); publisher.PublishMessage(message); }
protected override Task Execute(CancellationToken token) { log.LogInformation("Publishing..."); IFeedMessage message; if (string.IsNullOrEmpty(config.Image)) { message = new MultiItemMessage("Test Message", config.Text.Split(' ')); } else { message = new MediaMessage(config.Text, File.ReadAllBytes(config.Image)); } publisher.PublishMessage(message); return(Task.CompletedTask); }
public async Task ProcessMarket(string[] stockItems) { log.LogDebug("Processing market"); var sentimentTask = await twitterAnalysis.GetTrackingResults(new SentimentRequest(stockItems.Select(item => $"${item}").ToArray()) { Hours = new[] { 24 } }, CancellationToken.None) .ConfigureAwait(false); foreach (string stock in stockItems) { log.LogInformation("Processing {0}", stock); PredictionResult result = await instance().Start(stock).ConfigureAwait(false); double sellAccuracy = result.Performance.PerClassMatrices[0].Accuracy; double buyAccuracy = result.Performance.PerClassMatrices[1].Accuracy; string header = $"${stock} trading signals ({sellAccuracy * 100:F0}%/{buyAccuracy * 100:F0}%)"; var text = new StringBuilder(); if (sentimentTask.TryGetValue($"${stock}", out var sentiment)) { var sentimentValue = sentiment.First(); text.AppendFormat( "Average sentiment: {2}{0:F2}({1})\r\n", sentimentValue.Average, sentimentValue.TotalMessages, sentimentValue.GetEmoji()); } else { log.LogWarning("Not found sentiment for {0}", stock); } for (int i = 0; i < result.Predictions.Length || i < 2; i++) { MarketDirection prediction = result.Predictions[result.Predictions.Length - i - 1]; log.LogInformation("{2}, Predicted T-{0}: {1}\r\n", i, prediction, stock); string icon = prediction == MarketDirection.Buy ? Emoji.CHART_WITH_UPWARDS_TREND.Unicode : Emoji.CHART_WITH_DOWNWARDS_TREND.Unicode; text.AppendFormat("T-{0}: {2}{1}\r\n", i, prediction, icon); } var message = new MultiItemMessage(header, new[] { text.ToString() }); publisher.PublishMessage(message); } }