+1
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Plans for Telegram Support?
Collapse
X
-
Hello,
At OsloTrading we have developed a Script to send information about your trades to any Telegram´s channel or group.
You can request more information by email: [email protected]
Best regards.
Comment
-
Adding Telegram support is a bad idea.
It would dilute the support effort of the Ninja Trader Staff without adding anything significant and it would dilute the effectiveness of this forum as answers/help would then be spread out in different locations.
This forum has great features and a nicely searchable database of answers.
Further, do Telegram posts last forever or do they disappear after some time?
If they disappear then the support staff would likely be answering the same questions over and over...
Would the Telegram posts be easily searchable like this forum?
Telegram doesn't really have posts or threads right?
So it would be a mess.
What features do you think this forum is lacking that Telegram can do?
It sounds like the few here that want Telegram support are simply used to using Telegram and aren't considering the actual features...
Bad idea.
- Likes 1
Comment
-
-
Please add my vote to this request. Thanks a lot!
Comment
-
There is an easy way to incorporate NT with Telegram without having to use imports. You can use the native Telegram API found here. Telegram APIs
First create your bots and channels and get your token and chat Ids. There is plenty of info on the web on how to do that.
Then you would use it as so.
add your using statements in declarations
Code:using System.Net; using System.Net.Http;
Code:private const string API_TOKEN = "botXXXXX"; //Bot Token private const string chat_id = "-XXXXXX"; // you need the hyphen
Code:public void SendTelegramTextMessage(string Msg) { // string result = "Empty"; // you can use if you want to verify it worked string url = @"https://api.telegram.org/API_TOKEN/sendMessage?chat_id=" + CHAT_ID +"&text="+Msg; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) // result = reader.ReadToEnd(); // you can use if you want to verify it worked // return result }
To send an image file with a caption
Code:using System.Windows.Media.Imaging;
Code:public async Task SendPhoto (string Caption) { try { string url = @"https://api.telegram.org/" + API_TOKEN + "/sendPhoto?chat_id=" + chatId; string filePath = (FILEPath + "\\image.png"); var fileName = filePath.Split('\\').Last(); using (var form = new MultipartFormDataContent()) { form.Add(new StringContent(chatId.ToString(), Encoding.UTF8), "chat_id"); form.Add(new StringContent(Caption.ToString(), Encoding.UTF8), "caption"); form.Add(new StringContent("true", Encoding.UTF8), "disable_notification"); // Turn on or off the notifcation using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { form.Add(new StreamContent(fileStream), "photo", fileName); using (var client = new HttpClient()) { await client.PostAsync(url, form); } } } } catch (Exception ex) { Print(ex.ToString()); } }
Code:public async Task SendPhoto(string Caption, byte[] bytes) { MemoryStream ms = new MemoryStream(bytes); try { string url = @"https://api.telegram.org/" + API_TOKEN +"/sendPhoto?chat_id=" + chatId; using (var form = new MultipartFormDataContent()) { form.Add(new StringContent(chatId.ToString(), Encoding.UTF8), "chat_id"); form.Add(new StringContent(Caption.ToString(), Encoding.UTF8), "caption"); form.Add(new StringContent("true", Encoding.UTF8), "disable_notification"); // I disable notifications but you can turn this on. form.Add(new StreamContent(ms), "photo", "image"); using (var client = new HttpClient()) { await client.PostAsync(url, form); } } } catch (Exception ex) { Print(ex.ToString()); } }
Then I call it like so below. This example sends the current chart image screenshot using the override.
Code:using System.Threading; using System.Threading.Tasks; private static int threadLock = 0;
Code:public void SendTelegramChartImage(string Caption) { if(ChartControl == null) return; //Ensure a Strategy is Attached to a chart before continuing if (0 == Interlocked.Exchange(ref threadLock, 1)) //0 indicates that the method is not in use. { try { ForceRefresh(); this.ChartControl.Dispatcher.InvokeAsync(() => { NinjaTrader.Gui.Chart.Chart chart = Window.GetWindow(this.ChartControl) as NinjaTrader.Gui.Chart.Chart; RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Chart); if (screenCapture != null) // Just a boolean I use to control whether it does it or not. Remove it if you want. { try { BitmapFrame outputFrame = BitmapFrame.Create(screenCapture); using (MemoryStream ms = new MemoryStream()) { PngBitmapEncoder png = new PngBitmapEncoder(); png.Frames.Add(outputFrame); png.Save(ms); SendPhoto(Caption,ms.ToArray()); } } catch (IOException io) { NinjaTrader.Code.Output.Process(uniqueStrategy + ": Could not take Telegram Screenshot " + io, PrintTo.OutputTab1); } } }); } catch (Exception ex) { NinjaTrader.Code.Output.Process(uniqueStrategy + ": Could not save Telegram Screenshot " + ex, PrintTo.OutputTab1); } Interlocked.Exchange(ref threadLock, 0); //Release the lock } }
I hope this helps everyone.Last edited by cutzpr; 08-12-2021, 10:17 AM.
Comment
-
Hi guys, We have this script for Telegram connected to ninjatrader.
I think this will solve the problem for you. Greetings
- Likes 1
Comment
-
Originally posted by cutzpr View PostThere is an easy way to incorporate NT with Telegram without having to use imports. You can use the native Telegram API found here. Telegram APIs
First create your bots and channels and get your token and chat Ids. There is plenty of info on the web on how to do that.
Then you would use it as so.
add your using statements in declarations
Code:using System.Net; using System.Net.Http;
Code:private const string API_TOKEN = "botXXXXX"; //Bot Token private const string chat_id = "-XXXXXX"; // you need the hyphen
Code:public void SendTelegramTextMessage(string Msg) { // string result = "Empty"; // you can use if you want to verify it worked string url = @"https://api.telegram.org/API_TOKEN/sendMessage?chat_id=" + CHAT_ID +"&text="+Msg; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) // result = reader.ReadToEnd(); // you can use if you want to verify it worked // return result }
To send an image file with a caption
Code:using System.Windows.Media.Imaging;
Code:public async Task SendPhoto (string Caption) { try { string url = @"https://api.telegram.org/" + API_TOKEN + "/sendPhoto?chat_id=" + chatId; string filePath = (FILEPath + "\\image.png"); var fileName = filePath.Split('\\').Last(); using (var form = new MultipartFormDataContent()) { form.Add(new StringContent(chatId.ToString(), Encoding.UTF8), "chat_id"); form.Add(new StringContent(Caption.ToString(), Encoding.UTF8), "caption"); form.Add(new StringContent("true", Encoding.UTF8), "disable_notification"); // Turn on or off the notifcation using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { form.Add(new StreamContent(fileStream), "photo", fileName); using (var client = new HttpClient()) { await client.PostAsync(url, form); } } } } catch (Exception ex) { Print(ex.ToString()); } }
Code:public async Task SendPhoto(string Caption, byte[] bytes) { MemoryStream ms = new MemoryStream(bytes); try { string url = @"https://api.telegram.org/" + API_TOKEN +"/sendPhoto?chat_id=" + chatId; using (var form = new MultipartFormDataContent()) { form.Add(new StringContent(chatId.ToString(), Encoding.UTF8), "chat_id"); form.Add(new StringContent(Caption.ToString(), Encoding.UTF8), "caption"); form.Add(new StringContent("true", Encoding.UTF8), "disable_notification"); // I disable notifications but you can turn this on. form.Add(new StreamContent(ms), "photo", "image"); using (var client = new HttpClient()) { await client.PostAsync(url, form); } } } catch (Exception ex) { Print(ex.ToString()); } }
Then I call it like so below. This example sends the current chart image screenshot using the override.
Code:using System.Threading; using System.Threading.Tasks; private static int threadLock = 0;
Code:public void SendTelegramChartImage(string Caption) { if(ChartControl == null) return; //Ensure a Strategy is Attached to a chart before continuing if (0 == Interlocked.Exchange(ref threadLock, 1)) //0 indicates that the method is not in use. { try { ForceRefresh(); this.ChartControl.Dispatcher.InvokeAsync(() => { NinjaTrader.Gui.Chart.Chart chart = Window.GetWindow(this.ChartControl) as NinjaTrader.Gui.Chart.Chart; RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Chart); if (screenCapture != null) // Just a boolean I use to control whether it does it or not. Remove it if you want. { try { BitmapFrame outputFrame = BitmapFrame.Create(screenCapture); using (MemoryStream ms = new MemoryStream()) { PngBitmapEncoder png = new PngBitmapEncoder(); png.Frames.Add(outputFrame); png.Save(ms); SendPhoto(Caption,ms.ToArray()); } } catch (IOException io) { NinjaTrader.Code.Output.Process(uniqueStrategy + ": Could not take Telegram Screenshot " + io, PrintTo.OutputTab1); } } }); } catch (Exception ex) { NinjaTrader.Code.Output.Process(uniqueStrategy + ": Could not save Telegram Screenshot " + ex, PrintTo.OutputTab1); } Interlocked.Exchange(ref threadLock, 0); //Release the lock } }
I hope this helps everyone.
Text messages work, but no pics.
No errors or anything helpful.
Maybe that's because of the uniqueStrategy you're using? What does it contain?
Any ideas?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by lucasmelo152, 06-28-2021, 12:51 PM
|
8 responses
2,123 views
0 likes
|
Last Post
by Ymcapital
Today, 04:31 PM
|
||
Started by Creamers, 04-27-2024, 05:32 AM
|
11 responses
68 views
0 likes
|
Last Post
by Creamers
Today, 04:30 PM
|
||
Started by NM_eFe, 04-30-2024, 06:14 AM
|
5 responses
32 views
0 likes
|
Last Post
by NM_eFe
Today, 04:28 PM
|
||
Started by Jonker, 04-27-2024, 01:19 PM
|
2 responses
20 views
0 likes
|
Last Post
by Jonker
Today, 04:25 PM
|
||
Started by Max Baxter, 03-07-2019, 09:20 PM
|
8 responses
267 views
0 likes
|
Last Post
by Ymcapital
Today, 04:17 PM
|
Comment