Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Set up a Telegram Messenger bot for NT8 alerts

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Set up a Telegram Messenger bot for NT8 alerts

    To see if you can help me, Is there any way to set up a Telegram Messenger bot and receive messages and notifications from NT8? Is it possible to configure it from "share services" in the same way that the sending of alerts by email is configured?

    Thanks for your time.

    #2
    Hello Rober182,

    You will need to setup an SMTP share service first. Then you will be able to call SendMail() from a NinjaScript or from the Alerts window.

    Below is a link to a forum thread that discusses this.



    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks you, ChelseaB

      Comment


        #4
        somebody was working on it, i think on futures io but eventually gave up because telegram API or the library for it for C# made things a bit complicated.

        Comment


          #5
          Hello Folks:

          If you are looking for a NinjaTrader to Telegram alert system, we just launched one free. You can download and register here:

          Comment


            #6
            Hello waldoalvarez,

            As per our policy NinjaTrader does not allow promoting on the forums. As your link is intended to be helpful and is on topic I will this once make an exception and allow this to remain. However, moving forward please consider providing links to software on 3rd party sites in a private direct message.

            Kind regards.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello Rober182,

              You will need to setup an SMTP share service first. Then you will be able to call SendMail() from a NinjaScript or from the Alerts window.

              Below is a link to a forum thread that discusses this.


              You have much simpler solutions for sending text to a Telegram bot. For example, you can just call this function:

              public void SendMessage(string msg, string bottoken, string chatid)
              {

              bool sender = false;
              string url = "https://api.telegram.org/bot"+bottoken+"/sendMessage?chat_id="+chatid+"&parse_mode=html&tex t=";
              url = url + msg;

              using (var wb = new WebClient()){

              try
              {
              var response = wb.DownloadString(url);
              sender = true;
              }
              catch (Exception ex)
              {
              return;
              }

              }

              }

              Pls do not forget adding:
              using System.Net;

              If you want to also send chart images, that would require using Telegram.Bot dll

              Comment


                #8
                Originally posted by GillRymhes View Post

                You have much simpler solutions for sending text to a Telegram bot. For example, you can just call this function:

                public void SendMessage(string msg, string bottoken, string chatid)
                {

                bool sender = false;
                string url = "https://api.telegram.org/bot"+bottoken+"/sendMessage?chat_id="+chatid+"&parse_mode=html&tex t=";
                url = url + msg;

                using (var wb = new WebClient()){

                try
                {
                var response = wb.DownloadString(url);
                sender = true;
                }
                catch (Exception ex)
                {
                return;
                }

                }

                }

                Pls do not forget adding:
                using System.Net;

                If you want to also send chart images, that would require using Telegram.Bot dll
                Thanks for this. I tested it out and worked, but found you have an extra space in the string URL which was causing it to fail.

                string url = "https://api.telegram.org/bot"+bottoken+"/sendMessage?chat_id="+chatid+"&parse_mode=html&tex t=";

                [edit] that's odd, the space gets added by the forum?! anyway, you just need to remove the space in the text at the end of the string. Hope that helps.

                Comment


                  #9
                  If one wants to broadcast to a bot channel, how does one find the relevant chat_id of that bot channel? [The token is easy as it's provided at bot creation.]

                  Thanks.
                  Multi-Dimensional Managed Trading
                  jeronymite
                  NinjaTrader Ecosystem Vendor - Mizpah Software

                  Comment


                    #10
                    Originally posted by jeronymite View Post
                    If one wants to broadcast to a bot channel, how does one find the relevant chat_id of that bot channel? [The token is easy as it's provided at bot creation.]

                    Thanks.
                    I used: https://t.me/get_id_bot

                    Comment


                      #11
                      Thanks, timcjpfx . That has pointed me in the right direction.

                      Thanks.
                      Multi-Dimensional Managed Trading
                      jeronymite
                      NinjaTrader Ecosystem Vendor - Mizpah Software

                      Comment


                        #12
                        You can find more information about sending text+image messages to Telegram from Ninjatrader on this page (spanish):

                        Comment


                          #13
                          Originally posted by cls71 View Post
                          You can find more information about sending text+image messages to Telegram from Ninjatrader on this page (spanish):
                          https://www.supperia.com/enviar-mensajes-telegram/
                          That was very helpful. Thanks!

                          Comment


                            #14
                            cls71 Thanks. Helpful indeed. The Spanish was a bit of a challenge, but the Vivaldi browser has built-in translation that worked very well for this.

                            Thanks.
                            Multi-Dimensional Managed Trading
                            jeronymite
                            NinjaTrader Ecosystem Vendor - Mizpah Software

                            Comment


                              #15
                              Maybe someone finds this useful. I had a problem with sending screenshot to Telegram, a common thread error: The calling thread cannot access this object because a different thread owns it.
                              So I fixed it:

                              Code:
                              private void SendScreenshot()
                              {
                              SendScreenshotAsync();
                              }
                              private async Task SendScreenshotAsync()
                              {
                              RenderTargetBitmap screen = null;
                              await Dispatcher.BeginInvoke(new Action(() => { Chart = Window.GetWindow(ChartControl) as Chart; screen = Chart.GetScreenshot(ShareScreenshotType.Chart); }));
                              // if (Chart == null) Print("Chart null");
                              // if (screen == null) Print("screen null");
                              if (screen == null) return;
                              
                              BitmapFrame output = BitmapFrame.Create(screen);
                              byte[] bytes;
                              using (MemoryStream ms = new MemoryStream())
                              {
                              
                              PngBitmapEncoder png = new PngBitmapEncoder();
                              png.Frames.Add(output);
                              png.Save(ms);
                              bytes = ms.ToArray();
                              }
                              
                              try
                              {
                              //https://github.com/TelegramBots/Telegram.Bot/issues/867
                              //https://stackoverflow.com/questions/50768640/change-dns-in-windows-using-c-sharp
                              //set to 8.8.8.8
                              // System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12; // in .net 4.6 it's default, in 4.5 this code you need to use
                              MemoryStream ms = new MemoryStream(bytes);
                              await Bot.SendPhotoAsync(ChatID, ms);
                              ms.Dispose();
                              }
                              catch (Exception e)
                              {
                              Log("SendScreenshotAsync exception: " + e.ToString(), LogLevel.Error);
                              }
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by junkone, Today, 11:37 AM
                              2 responses
                              14 views
                              0 likes
                              Last Post junkone
                              by junkone
                               
                              Started by frankthearm, Yesterday, 09:08 AM
                              12 responses
                              44 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by quantismo, 04-17-2024, 05:13 PM
                              5 responses
                              35 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by proptrade13, Today, 11:06 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              35 views
                              0 likes
                              Last Post love2code2trade  
                              Working...
                              X