Send data from ctrader to a webpage
Send data from ctrader to a webpage
26 Oct 2018, 00:27
Hi,
Is there any way to send data from ctrader to a webpage? Say for example i want to send a MarketSeries or IndicatorDataSeries to my webpage and then plot the series on my webpage, how would i send the series from ctrader?. I'm thinking of using textfiles (writing the series to a txt file and then reading the txt in js or php and plotting from there) but this is highly inefficient. Is there any code to do this in real-time from ctrader?
Best Regards
Tansen
Replies
freemangreat
26 Oct 2018, 17:20
This needs to be altered for the POST request of the HTTP.
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; using System.IO; using System.Net; // https://docs.microsoft.com/en-us/dotnet/framework/network-programming/how-to-send-data-using-the-webrequest-class namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.Internet)] public class TestWebRequest : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } protected override void Initialize() { // Create a request for the URL. WebRequest request = WebRequest.Create ("https://pastebin.com/raw/q3t5DY1i"); // If required by the server, set the credentials. //request.Credentials = CredentialCache.DefaultCredentials; // Get the response. HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Display the status. Print(response.StatusDescription); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader (dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. Print(responseFromServer); // Cleanup the streams and the response. reader.Close (); dataStream.Close (); response.Close (); } public override void Calculate(int index){} } }
@freemangreat
PanagiotisCharalampous
26 Oct 2018, 09:25
Hi Tansen,
There is no easy way to do this. You will need to write your data in a file or database and then read it from there.
Best Regards,
Panagiotis
@PanagiotisCharalampous