New to cTrader OpenAPI, help please.

Created at 08 Nov 2023, 21:05
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Capt.Z-Fort.Builder's avatar

Capt.Z-Fort.Builder

Joined 03.06.2020

New to cTrader OpenAPI, help please.
08 Nov 2023, 21:05


Hello,
I'm experienced in cAlgo, but new to cTrader OpenAPI.  I've followed the Registering a New Application and got Credentials, I also installed the SDK package.

Now I want to build a connection and get some of my account basic information from the cTrader Endpoints, via the code below:

How should I finalize the code to use credentials and get some personal account information to display in the form?

Thanks.

using System;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using OpenAPI.Net;


namespace RecordPrice
{
    public class Program : Form
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new Program());
        }
        
        private OpenClient cTraderConnector = new OpenClient("live1.p.ctrader.com", 5034, TimeSpan.FromSeconds(10), useWebSocket: false);

        private Button startButton = new Button { Text = "Start Logging", Location = new System.Drawing.Point( 10, 10)              };
        private Button stopButton  = new Button { Text = "Stop Logging" , Location = new System.Drawing.Point(110, 10)              };
        private TextBox tx_Time    = new TextBox{ Text = "--:--:--"     , Location = new System.Drawing.Point( 10, 40), Width = 400 };
        
        public Program()
        {
            Text = "Price Logger App"; Width = 430; Height = 200;

            startButton.Click += StartLogging;
            stopButton.Click  += StopLogging;   stopButton.Enabled = false;
            tx_Time.Visible = true; tx_Time.ReadOnly = true;

            Controls.Add(startButton);
            Controls.Add(stopButton);
            Controls.Add(tx_Time);

        }
        
        private void StartLogging(object sender, EventArgs e)
        {
            startButton.Enabled = false;
            stopButton.Enabled = true;


            cTraderConnector.Connect();		// Initialize cTrader API connector with the credentials
            tx_Time.Text = cTraderConnector.AccountInformation.ToString();	// How to get some useful information and display at the TextBox?

        }
        
        private void StopLogging(object sender, EventArgs e)
        {
            startButton.Enabled = true;
            stopButton.Enabled = false;

        }

    }

}

 


@Capt.Z-Fort.Builder
Replies

PanagiotisCharalampous
09 Nov 2023, 06:37

Hi there,

Check the documentation and the examples here.

Best regards,

Panagiotis


@PanagiotisCharalampous