#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; #endregion using System.Net; using System.Net.Http; using Newtonsoft.Json; //This namespace holds Share adapters in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.ShareServices { public class Signl4webhook : ShareService { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Share Service here."; Name = "Signl4webhook"; Signl4APIUrl = @"https://connect.signl4.com/webhook/hf???d"; } else if (State == State.Configure) { } } public override async Task OnShare(string text, string alertType) { // place your share service logic here var data = new Data { // this is a specific object containing data read from the sensor Title = "Ninjatrader alert", Body = "alerted " + string.Format("{0:0.0} °C", text), TradeAlert = string.Format("{0:0.0} °C", alertType), PriceAlert = string.Format("{0:0.0}%", "blank") }; try { var response = await PostAsync(Signl4APIUrl, data); if (response == null) { return; } await response.Content.ReadAsStringAsync(); } catch (Exception ex) { // do something } } public static async Task<HttpResponseMessage> PostAsync<T>(string strUrl, T content) { var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }); HttpContent httpContent = null; if (content != null) { httpContent = new StringContent(JsonConvert.SerializeObject(content) , Encoding.UTF8, "application/json"); } return await client.PostAsync(strUrl, httpContent); } #region Properties [NinjaScriptProperty] [Display(Name = "Signl4APIUrl", Description = "url default", Order = 1, GroupName = "Parameters")] public string Signl4APIUrl { get; set; } #endregion } [JsonObject] public class Data { public string PriceAlert { get; set; } [JsonProperty(Order = 3)] public string TradeAlert { get; set; } [JsonProperty(Order = 2)] public string Body { get; set; } [JsonProperty(Order = 1)] public string Title { get; set; } } }
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!
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
NinjaTrader
how to call the shareservuce frin nt addib
Collapse
X
-
how to call the shareservuce frin nt addib
i created a shareservice for Sign4. how can i call it from my addon?
Code:Tags: None
-
Hello junkone,
All share services are called in the same way, you would use the Share method: https://ninjatrader.com/support/help...lightsub=share
You would need to have this service configured in the options menu and then call it using the name you provided for it.
Please let me know if I may be of additional assistance.JesseNinjaTrader Customer Service
-
i finally got around to working on this but it still does not work.
i have a video. there is nothing to configure. i put it all in the code.
Code:#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; #endregion using System.Net; using System.Timers; using Newtonsoft.Json; using System.IO; using System.Net; using System.Net.Http; //This namespace holds Add ons in this folder and is required. Do not change it. using Newtonsoft.Json; using System.Data.SqlClient; using Sharpbrake.Client; using System.Data; //This namespace holds Share adapters in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.ShareServices { public class PageMyself : ShareService { readonly string appKey = "keydCvGa3tg"; private string Signl4APIUrl = @"https://connect.signl4.com/webhook/url"; private AirbrakeNotifier airbrake = new AirbrakeNotifier(new AirbrakeConfig { ProjectId = "1s35", ProjectKey = "921976e809sd93f21fa60b0bb1" }); protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Share Service here."; Name = "PageMyself"; } else if (State == State.Configure) { } } public override async Task OnShare(string text, string imgFilePath) { // place your share service logic here var data = new Data { // this is a specific object containing data read from the sensor Title = "Ninjatrader alert", Body = "price alerted " + string.Format("{0:0.0} ", text), PriceAlert = string.Format("{0:0.0}%", "blank") }; try { var cli = new WebClient(); cli.Headers[HttpRequestHeader.ContentType] = "application/json";
}
catch (Exception e)
{
Print(e.StackTrace);
var notice = airbrake.BuildNotice(e);
var response = airbrake.NotifyAsync(notice).Result;
}
}
}
}
Comment
-
Hello junkone,
Thanks for the post.
Are you asking for help with the web request that you are doing or is some part of the share service not working?
I wouldn't be able to comment about the web request/json that you used however you can review the Twitter service for an example of connecting with an API.
Please let me know if I may be of additional assistance.
JesseNinjaTrader Customer Service
Comment
-
where is this error coming from? its not in my code. infact, i have commented all custom code. i just put the skeleton method here.
here is the skeleton code.
Code:#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; #endregion using System.Net; using System.Timers; using Newtonsoft.Json; using System.IO; using System.Net; using System.Net.Http; //This namespace holds Add ons in this folder and is required. Do not change it. using Newtonsoft.Json; using System.Data.SqlClient; using Sharpbrake.Client; using System.Data; //This namespace holds Share adapters in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.ShareServices { public class PageMyself : ShareService { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Share Service here."; Name = "PageMyself"; } else if (State == State.Configure) { } } public override async Task OnShare(string text, string imgFilePath) { // // place your share service logic here // var data = new Data // { // // this is a specific object containing data read from the sensor // Title = "Ninjatrader alert", // Body = "price alerted " + string.Format("{0:0.0} ", text), // PriceAlert = string.Format("{0:0.0}%", "blank") // }; // try // { // var cli = new WebClient(); // cli.Headers[HttpRequestHeader.ContentType] = "application/json"; // string response = cli.UploadString(Signl4APIUrl, JsonConvert.SerializeObject(data)); // } // catch (Exception e) // { // Print(e.StackTrace); // var notice = airbrake.BuildNotice(e); // var response = airbrake.NotifyAsync(notice).Result; // } } } }
Comment
-
Hello junkone,
I would highly suggest to use the existing share services as a learning guide, the error you are seeing is normal and would appear if you have not made a complete service. By default a brand new script or shell will not work, you would need to have set IsConfigured = true at some point in your service depending on your needs. For example the twitter sets this after connecting to the api in the settings window. The others may set this in set defaults if there is no other configuration to be made.
Please let me know if I may be of additional assistance.
JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Stanfillirenfro, Today, 07:23 AM
|
1 response
3 views
0 likes
|
Last Post Today, 07:37 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
2 responses
21 views
0 likes
|
Last Post Today, 07:24 AM | ||
Started by olisav57, Yesterday, 07:39 PM
|
1 response
9 views
0 likes
|
Last Post Today, 07:23 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
7 responses
944 views
0 likes
|
Last Post
by Jquiroz1975
Today, 07:21 AM
|
||
Started by oviejo, Today, 12:28 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:20 AM |
Comment