Skip to content

IServer

interface cAlgo.API.Internals

DesktopCLICloud

Server related information.

Definition

public interface IServer

Namespace: cAlgo.API.Internals · Group: Application

Examples

using cAlgo.API;

namespace cAlgo
{
    // This sample indicator shows how to use Server object to get data related to server and connection
    public partial class ServerSample : Indicator
    {
        private TextBlock _isConnectedTextBlock;

        protected override void Initialize()
        {
            var grid = new Grid(4, 2)
            {
                BackgroundColor = Color.Gold,
                Opacity = 0.6,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
            };

            var style = new Style();

            style.Set(ControlProperty.Padding, 5);
            style.Set(ControlProperty.Margin, 5);
            style.Set(ControlProperty.FontWeight, FontWeight.ExtraBold);
            style.Set(ControlProperty.BackgroundColor, Color.Black);

            grid.AddChild(new TextBlock { Text = "Server Info", Style = style, HorizontalAlignment = HorizontalAlignment.Center }, 0, 0, 1, 2);

            grid.AddChild(new TextBlock { Text = "Time", Style = style }, 1, 0);
            grid.AddChild(new TextBlock { Text = Server.Time.ToString("o"), Style = style }, 1, 1);

            grid.AddChild(new TextBlock { Text = "Time (UTC)", Style = style }, 2, 0);
            grid.AddChild(new TextBlock { Text = Server.TimeInUtc.ToString("o"), Style = style }, 2, 1);

            grid.AddChild(new TextBlock { Text = "Is Connected", Style = style }, 3, 0);

            _isConnectedTextBlock = new TextBlock
            {
                Text = Server.IsConnected ? "Yes" : "No",
                Style = style,
            };

            Server.Connected += () => _isConnectedTextBlock.Text = "Yes";
            Server.Disconnected += () => _isConnectedTextBlock.Text = "No";

            grid.AddChild(_isConnectedTextBlock, 3, 1);

            Chart.AddControl(grid);
        }

        public override void Calculate(int index)
        {
        }
    }
}
import clr
clr.AddReference("cAlgo.API")

from cAlgo.API import *

class ServerSample():
    def initialize(self):
        grid = Grid(4, 2)
        grid.BackgroundColor = Color.Gold
        grid.Opacity = 0.6
        grid.HorizontalAlignment = HorizontalAlignment.Center
        grid.VerticalAlignment = VerticalAlignment.Center

        self.style = Style()

        self.style.Set(ControlProperty.Padding, 5)
        self.style.Set(ControlProperty.Margin, 5)
        self.style.Set(ControlProperty.FontWeight, FontWeight.ExtraBold)
        self.style.Set(ControlProperty.BackgroundColor, Color.Black)

        titleTextBlock = self.get_text_block("Server Info")
        titleTextBlock.HorizontalAlignment = HorizontalAlignment.Center

        grid.AddChild(titleTextBlock, 0, 0, 1, 2)
        grid.AddChild(self.get_text_block("Time"), 1, 0)
        grid.AddChild(self.get_text_block(str(api.Server.Time)), 1, 1)
        grid.AddChild(self.get_text_block("Time (UTC)"), 2, 0)
        grid.AddChild(self.get_text_block(str(api.Server.TimeInUtc)), 2, 1)
        grid.AddChild(self.get_text_block("Is Connected"), 3, 0)

        self.isConnectedTextBlock = self.get_text_block("Yes" if api.Server.IsConnected else "No")

        api.Server.Connected += self.on_server_connected
        api.Server.Disconnected += self.on_server_disconnected

        grid.AddChild(self.isConnectedTextBlock, 3, 1)

        api.Chart.AddControl(grid)

    def on_server_connected(self):
        self.isConnectedTextBlock.Text = "Yes"

    def on_server_disconnected(self):
        self.isConnectedTextBlock.Text = "No"

    def get_text_block(self, text):
        textBlock = TextBlock()
        textBlock.Text = text
        textBlock.Style = self.style
        return textBlock
{
  "AccessRights": "None",
  "TimeZone": "UTC",
  "IsOverlay": true
}

Properties

Name Description
IsConnectedDesktopCLICloudbool Indicates current connection status with the server
TimeDesktopCLICloudDateTime Returns the server time.
TimeInUtcDesktopCLICloudDateTime Returns the server time in UTC.

Events

Name Description
ConnectedDesktopCLICloudAction Event raised when successfully connected with the server
DisconnectedDesktopCLICloudAction Disconnected - Event raised when connection with the server is lost