-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
44 lines (35 loc) · 1.94 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Newtonsoft.Json.Linq;
using PETR_Robot;
using System.Diagnostics;
using Telegram.Bot;
using Telegram.Bot.Types;
// PETR-Robot Main
Stopwatch runTime = Stopwatch.StartNew();
Console.WriteLine("PETR-Robot started! Time now is: BR {0} US {1}", MarketHours.GetBraTime(), MarketHours.GetUsaTime());
string telegramBotToken = Utils.GetEnvironmentVariable<string>("TELEGRAM_BOT_TOKEN");
long groupChatID = Utils.GetEnvironmentVariable<long>("GROUP_CHAT_ID");
int fixedMessageID = Utils.GetEnvironmentVariable<int>("FIXED_MESSAGE_ID");
bool showLogMessage = Utils.GetEnvironmentVariable<bool>("SHOW_LOG_MESSAGE");
var bot = new TelegramBotClient(telegramBotToken);
var chatID = new ChatId(groupChatID);
if (true)
{
var b3QuotePETR4 = await ApiCalls.GetB3Quote("PETR4");
var b3QuotePETR3 = await ApiCalls.GetB3Quote("PETR3");
if (b3QuotePETR4.Item1 > 0)
{
// Choose the circle color based on the stock percentage
string circlePETR4 = b3QuotePETR4.Item2 < 0 ? Emoji.redCircle : Emoji.greenCircle;
string circlePETR3 = b3QuotePETR3.Item2 < 0 ? Emoji.redCircle : Emoji.greenCircle;
string b3PETR4Percent = string.Format("{0:0.0}%", b3QuotePETR4.Item2);
string b3PETR3Percent = string.Format("{0:0.0}%", b3QuotePETR3.Item2);
string message = String.Format("{0}PETR4: {1} {2}% {3}PETR3: {4} {5}%\n └ {5} com delay 15 min",
circlePETR4, b3QuotePETR4.Item1, b3PETR4Percent, circlePETR3, b3QuotePETR3.Item1, b3PETR3Percent, DateTime.Now.ToString());
var B3PetrQuoteMessage = await bot.EditMessageTextAsync(chatID, fixedMessageID, message);
}
}
runTime.Stop();
string finishMessage = "PETR-Robot finish! Total run time is: " + runTime.Elapsed.ToString();
Console.WriteLine(finishMessage);
if (showLogMessage)
await bot.SendTextMessageAsync(chatID, "https://br.investing.com/news/economic-indicators/calendario-economico-investidores-estarao-atentos-a-inflacao-no-brasil-e-nos-eua-1218646");