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; break;
} }
} }
string triggers = "";
if(isStSwitch){ if(isStSwitch){
Picasso.DrawChart(reports, max ,min, maxVol, symbol); triggers += "Switched SuperTrend\n";
await Messenger.instance.SendLastChart(filename:symbol);
await Messenger.instance.SendMessage($"`{symbol}` switched the SuperTrend lines. Current price: {reports[reports.Count-1].Close}");
} }
if(reports[reports.Count-1].TGOR){ if(reports[reports.Count-1].TGOR && !reports[reports.Count-2].TGOR){//Ignore if two in row
Picasso.DrawChart(reports, max ,min, maxVol, symbol); triggers += "Price dropped\n";
await Messenger.instance.SendLastChart(filename:symbol);
await Messenger.instance.SendMessage($"`{symbol}` Price dropped. Current price: {reports[reports.Count-1].Close}");
} }
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() async void KeepUpdatingCandles()

View File

@ -6,19 +6,14 @@ public static class CoinsList{
"XLMUSDT", "XLMUSDT",
"SOLUSDT", "SOLUSDT",
"AVAXUSDT", "AVAXUSDT",
"VIRTUALUSDT",
"ENAUSDT", "ENAUSDT",
"HIVEUSDT", "HIVEUSDT",
"STEEMUSDT", "STEEMUSDT",
"MOVEUSDT", "MOVEUSDT",
"DOGEUSDT", "DOGEUSDT",
"SHIBAUSDT",
"INUUSDT",
"PEPEUSDT", "PEPEUSDT",
"AIXBTUSDT",
"RLCUSDT", "RLCUSDT",
"ACTUSDT", "ACTUSDT",
"CHILLGUYUSDT",
"STGUSDT", "STGUSDT",
"ONEUSDT", "ONEUSDT",
"LINKUSDT", "LINKUSDT",
@ -29,6 +24,14 @@ public static class CoinsList{
"JUPUSDT", "JUPUSDT",
"LUNAUSDT", "LUNAUSDT",
"DUSKUSDT", "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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Telegram.Bot; using Telegram.Bot;
@ -8,30 +9,70 @@ using Telegram.Bot.Exceptions;
using Telegram.Bot.Polling; using Telegram.Bot.Polling;
using Telegram.Bot.Types; using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.Enums;
namespace SignalsTest namespace SignalsTest
{ {
public class Messenger public class Messenger
{ {
TelegramBotClient botClient; TelegramBotClient botClient;
private static Messenger m_instance; private static Messenger m_instance;
public static Messenger instance { get { if (m_instance == null) { m_instance = new Messenger(); } return 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 = "@doralockscryptosignals";
public const string chatId_test = "@SignalTestPrivate";
// public const string chatId = "@doralockscryptosignals";
//prod:doralockscryptosignals //prod:doralockscryptosignals
//test:SignalTestPrivate //test:SignalTestPrivate
public async Task SendMessage(string text, string chat =chatId) // public async Task SendMessage(string text, string chat =chatId)
{ // {
await botClient.SendTextMessageAsync(chat, text); // 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"){ public async void InitializeScheduler(){
FileStream fsSource = new FileStream($"{filename}.png", FileMode.Open, FileAccess.Read); string _chatId = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? chatId_test : chatId;
InputFile photo = InputFile.FromStream(fsSource);
await botClient.SendPhotoAsync(chat, photo); while(true){
Console.WriteLine("Photo sent success"); 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() public Messenger()
@ -44,6 +85,8 @@ namespace SignalsTest
{ {
AllowedUpdates = Array.Empty<UpdateType>() // receive all update types except ChatMember related updates 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) private static void Main(string[] args)
{ {
Console.WriteLine("Initializing Messiah"); Console.WriteLine("Initializing Messiah");
Messenger.instance.SendMessage("Rebooted bot"); Messenger.instance.ScheduleMessage("Rebooted bot");
for (int i=0; i < CoinsList.symbols.Count; i++){ for (int i=0; i < CoinsList.symbols.Count; i++){
CoinWatch btcWatch = new CoinWatch(CoinsList.symbols[i], i); CoinWatch btcWatch = new CoinWatch(CoinsList.symbols[i], i);
btcWatch.PriceUpdated += CoinWatch_OnPriceUpdate; btcWatch.PriceUpdated += CoinWatch_OnPriceUpdate;
@ -34,7 +34,7 @@ class Program
} }
string msg = $"{failedList.Count} Failed out of {watches.Count}. Failed list: \n{commasList}"; string msg = $"{failedList.Count} Failed out of {watches.Count}. Failed list: \n{commasList}";
Console.WriteLine(msg); Console.WriteLine(msg);
Messenger.instance.SendMessage(msg); Messenger.instance.ScheduleMessage(msg);
} }
private static void CoinWatch_OnPriceUpdate(Object? sender,BinanceTradeData data) 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.AssemblyCompanyAttribute("SignalsTestCmd")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [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.AssemblyProductAttribute("SignalsTestCmd")]
[assembly: System.Reflection.AssemblyTitleAttribute("SignalsTestCmd")] [assembly: System.Reflection.AssemblyTitleAttribute("SignalsTestCmd")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
d51df1548d76f8853335b1b69514870239705cd0805ac5ee723719964382763d 60efa4460d709a625170ed984e861ea72cc83eff5a76a9feab2ed4db32115f73