Messenger scheduler

This commit is contained in:
Sewmina 2025-01-09 11:38:30 +05:30
parent 803e1a6efc
commit 86e55e5688
19 changed files with 78 additions and 26 deletions

BIN
SignalsTestCmd/ARUSDT.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

BIN
SignalsTestCmd/CFXUSDT.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

View File

@ -111,16 +111,22 @@ namespace SignalsTest
break;
}
}
string triggers = "";
if(isStSwitch){
Picasso.DrawChart(reports, max ,min, maxVol, symbol);
await Messenger.instance.SendLastChart(filename:symbol);
await Messenger.instance.SendMessage($"`{symbol}` switched the SuperTrend lines. Current price: {reports[reports.Count-1].Close}");
triggers += "Switched SuperTrend\n";
}
if(reports[reports.Count-1].TGOR){
Picasso.DrawChart(reports, max ,min, maxVol, symbol);
await Messenger.instance.SendLastChart(filename:symbol);
await Messenger.instance.SendMessage($"`{symbol}` Price dropped. Current price: {reports[reports.Count-1].Close}");
if(reports[reports.Count-1].TGOR && !reports[reports.Count-2].TGOR){//Ignore if two in row
triggers += "Price dropped\n";
}
if(triggers!= ""){
Picasso.DrawChart(reports, max ,min, maxVol, symbol);
string message = $"`{symbol}` {triggers} \nCurrent price: {reports[reports.Count-1].Close}";
Messenger.instance.ScheduleMessage(message, symbol);
}
}
async void KeepUpdatingCandles()

View File

@ -6,19 +6,14 @@ public static class CoinsList{
"XLMUSDT",
"SOLUSDT",
"AVAXUSDT",
"VIRTUALUSDT",
"ENAUSDT",
"HIVEUSDT",
"STEEMUSDT",
"MOVEUSDT",
"DOGEUSDT",
"SHIBAUSDT",
"INUUSDT",
"PEPEUSDT",
"AIXBTUSDT",
"RLCUSDT",
"ACTUSDT",
"CHILLGUYUSDT",
"STGUSDT",
"ONEUSDT",
"LINKUSDT",
@ -29,6 +24,14 @@ public static class CoinsList{
"JUPUSDT",
"LUNAUSDT",
"DUSKUSDT",
"SUIUSDT"
"SUIUSDT",
"INJUSDT",
"FILUSDT",
"GRTUSDT",
"HBARUSDT",
"CFXUSDT",
"TLMUSDT",
"NEARUSDT",
"FORTHUSDT"
];
}

BIN
SignalsTestCmd/LINKUSDT.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Telegram.Bot;
@ -8,30 +9,70 @@ using Telegram.Bot.Exceptions;
using Telegram.Bot.Polling;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
namespace SignalsTest
{
public class Messenger
{
TelegramBotClient botClient;
private static Messenger m_instance;
public static Messenger instance { get { if (m_instance == null) { m_instance = new Messenger(); } return m_instance; } }
public const string chatId = "@doralockscryptosignals";
public const string chatId_test = "@SignalTestPrivate";
// public const string chatId = "@doralockscryptosignals";
//prod:doralockscryptosignals
//test:SignalTestPrivate
public async Task SendMessage(string text, string chat =chatId)
{
await botClient.SendTextMessageAsync(chat, text);
// public async Task SendMessage(string text, string chat =chatId)
// {
// await botClient.SendTextMessageAsync(chat, text);
// }
// public async Task SendLastChart(string chat = chatId, string filename="test"){
// FileStream fsSource = new FileStream($"{filename}.png", FileMode.Open, FileAccess.Read);
// InputFile photo = InputFile.FromStream(fsSource);
// await botClient.SendPhotoAsync(chat, photo);
// Console.WriteLine("Photo sent success");
// }
public Dictionary<string,string> messagesSchedule = new Dictionary<string, string>();
public void ScheduleMessage(string text, string filename=""){
messagesSchedule.Add(text,filename);
}
public async Task SendLastChart(string chat = chatId, string filename="test"){
FileStream fsSource = new FileStream($"{filename}.png", FileMode.Open, FileAccess.Read);
InputFile photo = InputFile.FromStream(fsSource);
await botClient.SendPhotoAsync(chat, photo);
Console.WriteLine("Photo sent success");
public async void InitializeScheduler(){
string _chatId = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? chatId_test : chatId;
while(true){
await Task.Delay(3500);
if(messagesSchedule.Count <=0){
continue;
}
string message = messagesSchedule.Keys.ElementAt(0);
string filename = messagesSchedule[message];
try{
if(filename.Length < 2){
await botClient.SendTextMessageAsync(_chatId, message);
}else{
FileStream fsSource = new FileStream($"{filename}.png", FileMode.Open, FileAccess.Read);
InputFile photo = InputFile.FromStream(fsSource);
await botClient.SendPhotoAsync(_chatId, photo,caption: message);
}
messagesSchedule.Remove(message);
}catch(Exception e){
Console.WriteLine($"Error occured while sending {message} to {filename}");
Console.WriteLine(e.ToString());
}
}
}
public Messenger()
@ -44,6 +85,8 @@ namespace SignalsTest
{
AllowedUpdates = Array.Empty<UpdateType>() // receive all update types except ChatMember related updates
};
InitializeScheduler();
}
}
}

View File

@ -9,7 +9,7 @@ class Program
private static void Main(string[] args)
{
Console.WriteLine("Initializing Messiah");
Messenger.instance.SendMessage("Rebooted bot");
Messenger.instance.ScheduleMessage("Rebooted bot");
for (int i=0; i < CoinsList.symbols.Count; i++){
CoinWatch btcWatch = new CoinWatch(CoinsList.symbols[i], i);
btcWatch.PriceUpdated += CoinWatch_OnPriceUpdate;
@ -34,7 +34,7 @@ class Program
}
string msg = $"{failedList.Count} Failed out of {watches.Count}. Failed list: \n{commasList}";
Console.WriteLine(msg);
Messenger.instance.SendMessage(msg);
Messenger.instance.ScheduleMessage(msg);
}
private static void CoinWatch_OnPriceUpdate(Object? sender,BinanceTradeData data)

BIN
SignalsTestCmd/RLCUSDT.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 84 KiB

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("SignalsTestCmd")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e30de2471325024a3d1beb937a02157b4f10643d")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+803e1a6efcd9f9c8634f90e384fcb9d1e1e5735b")]
[assembly: System.Reflection.AssemblyProductAttribute("SignalsTestCmd")]
[assembly: System.Reflection.AssemblyTitleAttribute("SignalsTestCmd")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
d51df1548d76f8853335b1b69514870239705cd0805ac5ee723719964382763d
60efa4460d709a625170ed984e861ea72cc83eff5a76a9feab2ed4db32115f73