Followed YouTube video: "Lesson #4 - How to Code Telegram Alerts" and when an instance is run; e.g., EURUSD, the log throws the following error:
ERROR: Method not found: 'System.Net.Http.Json.JsonContent System.Net.Http.Json.JsonContent.Create(System.Object, System.Type, System.Net.Http.Headers.MediaTypeHeaderValue, System.Text.Json.JsonSerializerOptions)'.
Can anyone help me please?
using System;
using System.Net;
using cAlgo.API;
using cAlgo.API.Indicators;
using Telegram.Bot;
namespace cAlgo
{
[Levels(30, 50, 70)]
[Indicator(AccessRights = AccessRights.FullAccess, IsOverlay = false)]
public class DemoTelegramAlerts : Indicator
{
private readonly string _onInitializedMessage = $"{nameof(DemoTelegramAlerts)} initialized.";
#region User settings
[Parameter("Number Of Periods", DefaultValue = 14, Group = "Indicator Data",
MaxValue = 100, MinValue = 1)]
public int NumberOfPeriods { get; set; }
[Parameter("Data Stage", Group = "Indicator Data")]
public DataSeries DataSourceStage { get; set; }
[Parameter("Upper Threshold", DefaultValue = 70, Group = "Indicator Values")]
public int UpperThreshold { get; set; }
[Parameter("Lower Threshold", DefaultValue = 30, Group = "Indicator Values")]
public int LowerThreshold { get; set; }
[Parameter("Send Telegram?", DefaultValue = true, Group = "Telegram Notifications")]
public bool SendTelegramAlerts { get; set; }
[Parameter("Bot Token", DefaultValue = "XXXXXXXXXXXXXXXXXXXXXX",
Group = "Telegram Notifications")]
public string TelegramBotToken { get; set; }
[Parameter("Chat ID", DefaultValue = "0000000000",
Group = "Telegram Notifications")]
public string TelegramChatId { get; set; }
[Output("Main", PlotType = PlotType.Line, LineColor = "LimeGreen", Thickness = 2)]
public IndicatorDataSeries Result { get; set; }
#endregion
public RelativeStrengthIndex Rsi { get; set; }
protected override void Initialize()
{
Rsi = Indicators.RelativeStrengthIndex(DataSourceStage, NumberOfPeriods);
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
SendTelegram(_onInitializedMessage);
Print(_onInitializedMessage);
}
public override void Calculate(int index)
{
Result[index] = Rsi.Result[index];
}
public async void SendTelegram(string telegramMessage)
{
try
{
TelegramBotClient bot = new(TelegramBotToken );
Telegram.Bot.Types.Message sentMessage = await bot.SendMessage(TelegramChatId, telegramMessage);
Print($"Telegram message sent: {sentMessage.Text}");
}
catch (Exception ex)
{
Print("ERROR: " + ex.Message);
}
}
}
}
Note: Bot token and Chat ID have been purposely modified for security reasons.