Skip to content

IAccount

Summary

Contains the current account information.

Signature

1
public abstract interface IAccount

Namespace

cAlgo.API.Internals

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
 // Account Properties
 // Current Account Balance
 var balance = Account.Balance;
 // Current Account Currency e.g. EUR
 var currency = Account.Asset.Name;
 // Current Account Equity
    var equity = Account.Equity;
    // Current Account Free Margin
 var freeMargin = Account.FreeMargin;
 // Current Account Margin
    var margin = Account.Margin;
 //Margin Level = Equity / Margin * 100
    var marginLevel = Account.MarginLevel;
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 using cAlgo.API;
 namespace cAlgo
 {
     // This sample indicator shows how to use Account object properties to get your trading account data
     [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
     public class AccountSample : Indicator
     {
         protected override void Initialize()
         {
             var grid = new Grid(16, 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 = "Account Info", Style = style, HorizontalAlignment = HorizontalAlignment.Center }, 0, 0, 1, 2);
             grid.AddChild(new TextBlock { Text = "Type", Style = style }, 1, 0);
             grid.AddChild(new TextBlock { Text = Account.AccountType.ToString(), Style = style }, 1, 1);
             grid.AddChild(new TextBlock { Text = "Is Live", Style = style }, 2, 0);
             grid.AddChild(new TextBlock { Text = Account.IsLive.ToString(), Style = style }, 2, 1);
             grid.AddChild(new TextBlock { Text = "Balance", Style = style }, 3, 0);
             grid.AddChild(new TextBlock { Text = Account.Balance.ToString(), Style = style }, 3, 1);
             grid.AddChild(new TextBlock { Text = "Broker Name", Style = style }, 4, 0);
             grid.AddChild(new TextBlock { Text = Account.BrokerName, Style = style }, 4, 1);
             grid.AddChild(new TextBlock { Text = "Currency", Style = style }, 5, 0);
             grid.AddChild(new TextBlock { Text = Account.Asset.Name, Style = style }, 5, 1);
             grid.AddChild(new TextBlock { Text = "Number", Style = style }, 6, 0);
             grid.AddChild(new TextBlock { Text = Account.Number.ToString(), Style = style }, 6, 1);
             grid.AddChild(new TextBlock { Text = "Equity", Style = style }, 7, 0);
             grid.AddChild(new TextBlock { Text = Account.Equity.ToString(), Style = style }, 7, 1);
             grid.AddChild(new TextBlock { Text = "Free Margin", Style = style }, 8, 0);
             grid.AddChild(new TextBlock { Text = Account.FreeMargin.ToString(), Style = style }, 8, 1);
             grid.AddChild(new TextBlock { Text = "Margin", Style = style }, 9, 0);
             grid.AddChild(new TextBlock { Text = Account.Margin.ToString(), Style = style }, 9, 1);
             grid.AddChild(new TextBlock { Text = "Margin Level", Style = style }, 10, 0);
             grid.AddChild(new TextBlock { Text = Account.MarginLevel.ToString(), Style = style }, 10, 1);
             grid.AddChild(new TextBlock { Text = "Precise Leverage", Style = style }, 11, 0);
             grid.AddChild(new TextBlock { Text = Account.PreciseLeverage.ToString(), Style = style }, 11, 1);
             grid.AddChild(new TextBlock { Text = "Stop Out Level", Style = style }, 12, 0);
             grid.AddChild(new TextBlock { Text = Account.StopOutLevel.ToString(), Style = style }, 12, 1);
             grid.AddChild(new TextBlock { Text = "Unrealized Gross Profit", Style = style }, 13, 0);
             grid.AddChild(new TextBlock { Text = Account.UnrealizedGrossProfit.ToString(), Style = style }, 13, 1);
             grid.AddChild(new TextBlock { Text = "Unrealized Net Profit", Style = style }, 14, 0);
             grid.AddChild(new TextBlock { Text = Account.UnrealizedNetProfit.ToString(), Style = style }, 14, 1);
             grid.AddChild(new TextBlock { Text = "User Id", Style = style }, 15, 0);
             grid.AddChild(new TextBlock { Text = Account.UserId.ToString(), Style = style }, 15, 1);
             Chart.AddControl(grid);
         }
         public override void Calculate(int index)
         {
         }
     }
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
 # Account Properties
 # Current Account Balance
 balance = api.Account.Balance
 # Current Account Currency e.g. EUR
 currency = api.Account.Asset.Name
 # Current Account Equity
    equity = api.Account.Equity
    # Current Account Free Margin
 var freeMargin = api.Account.FreeMargin
 # Current Account Margin
    margin = api.Account.Margin
 # Margin Level = Equity / Margin * 100
    marginLevel = api.Account.MarginLevel
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 import clr
 clr.AddReference("cAlgo.API")
 from cAlgo.API import *
 class AccountSample():
     def initialize(self):
         grid = Grid(16, 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)
         headerTextBox = self.getTextBlock("Account Info")
         headerTextBox.HorizontalAlignment = HorizontalAlignment.Center
         grid.AddChild(headerTextBox, 0, 0, 1, 2)
         grid.AddChild(self.getTextBlock("Type"), 1, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.AccountType)), 1, 1)
         grid.AddChild(self.getTextBlock("Is Live"), 2, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.IsLive)), 2, 1)
         grid.AddChild(self.getTextBlock("Balance"), 3, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.Balance)), 3, 1)
         grid.AddChild(self.getTextBlock("Broker Name"), 4, 0)
         grid.AddChild(self.getTextBlock(api.Account.BrokerName), 4, 1)
         grid.AddChild(self.getTextBlock("Currency"), 5, 0)
         grid.AddChild(self.getTextBlock(api.Account.Asset.Name), 5, 1)
         grid.AddChild(self.getTextBlock("Number"), 6, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.Number)), 6, 1)
         grid.AddChild(self.getTextBlock("Equity"), 7, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.Equity)), 7, 1)
         grid.AddChild(self.getTextBlock("Free Margin"), 8, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.FreeMargin)), 8, 1)
         grid.AddChild(self.getTextBlock("Margin"), 9, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.Margin)), 9, 1)
         grid.AddChild(self.getTextBlock("Margin Level"), 10, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.MarginLevel)), 10, 1)
         grid.AddChild(self.getTextBlock("Precise Leverage"), 11, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.PreciseLeverage)), 11, 1)
         grid.AddChild(self.getTextBlock("Stop Out Level"), 12, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.StopOutLevel)), 12, 1)
         grid.AddChild(self.getTextBlock("Unrealized Gross Profit"), 13, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.UnrealizedGrossProfit)), 13, 1)
         grid.AddChild(self.getTextBlock("Unrealized Net Profit"), 14, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.UnrealizedNetProfit)), 14, 1)
         grid.AddChild(self.getTextBlock("User Id"), 15, 0)
         grid.AddChild(self.getTextBlock(str(api.Account.UserId)), 15, 1)
         api.Chart.AddControl(grid)
     def getTextBlock(self, text):
         textBlock = TextBlock()
         textBlock.Text = text
         textBlock.Style = self.style
         return textBlock

Properties

AccountType

Summary

Returns the current account type.

Signature

1
public abstract AccountType AccountType {get;}

Return Value

AccountType

Balance

Summary

Returns the balance of the current account.

Signature

1
public abstract double Balance {get;}

Return Value

double

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
 double balanceBefore;
 double balanceAfter;
 protected override void OnStart()
 {
    // store the balance upon start up of the robot
    balanceBefore = Account.Balance;
 }
 protected override void OnStop()
 {
     // Store the balance upon stop of the robot.
     balanceAfter = Account.Balance;
     // print the difference
    Print("The difference of balanceBefore and balanceAfter is: {0}", balanceBefore-balanceAfter);
 }
1
2
 if ( Account.Balance <= 0 )
     Stop();
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 import clr
 clr.AddReference("cAlgo.API")
 # Import cAlgo API types
 from cAlgo.API import *
 # Import trading wrapper functions
 from robot_wrapper import *
 class Test():
     def on_start(self):
         # store the balance upon start up of the robot
         self.balanceBefore = api.Account.Balance
     def on_stop(self):
         # Store the balance upon stop of the robot.
         balanceAfter = api.Account.Balance
         # print the difference
         print(f"The difference of balanceBefore and balanceAfter is: {self.balanceBefore-balanceAfter}")
1
2
 if api.Account.Balance <= 0:
     api.Stop()

Equity

Summary

Represents the equity of the current account (balance minus Unrealized Net Loss plus Unrealized Net Profit plus Bonus).

Signature

1
public abstract double Equity {get;}

Return Value

double

Examples

1
 Print("The equity of this account is: {0}", Account.Equity);
1
 print(f"The equity of this account is: {api.Account.Equity}")

Margin

Summary

Represents the margin of the current account.

Signature

1
public abstract double Margin {get;}

Return Value

double

Examples

1
 Print("The margin of this account is: {0}", Account.Margin);
1
 print(f"The margin of this account is: {api.Account.Margin}")

FreeMargin

Summary

Represents the free margin of the current account.

Signature

1
public abstract double FreeMargin {get;}

Return Value

double

Examples

1
 Print("The free margin of this account is: {0}", Account.FreeMargin);
1
 print(f"The free margin of this account is: {api.Account.FreeMargin}")

MarginLevel

Summary

Represents the margin level of the current account.Margin Level (in %) is calculated using this formula:Equity / Margin * 100

Signature

1
public abstract double? MarginLevel {get;}

Return Value

double?

Examples

1
 Print("The marginLevel of this account is: {0}", Account.MarginLevel);
1
 print(f"The marginLevel of this account is: {api.Account.MarginLevel}")

IsLive

Summary

Defines if the account is Live or Demo. True if the Account is Live, False if it is a Demo.

Signature

1
public abstract bool IsLive {get;}

Return Value

bool

Examples

1
2
3
4
 if (Account.IsLive)
     Print("Live Account");
 else
     Print("Demo Account");
1
2
3
4
 if api.Account.IsLive:
     print("Live Account")
 else:
     print("Demo Account")

Number

Summary

Returns the number of the current account, e.g. 123456.

Signature

1
public abstract int Number {get;}

Return Value

int

BrokerName

Summary

Returns the broker name of the current account.

Signature

1
public abstract string BrokerName {get;}

Return Value

string

UnrealizedGrossProfit

Summary

Gets the Unrealized Gross profit value.

Signature

1
public abstract double UnrealizedGrossProfit {get;}

Return Value

double

UnrealizedNetProfit

Summary

Gets the Unrealized Net profit value.

Signature

1
public abstract double UnrealizedNetProfit {get;}

Return Value

double

PreciseLeverage

Summary

Gets the precise account leverage value.

Signature

1
public abstract double PreciseLeverage {get;}

Return Value

double

Examples

1
 var leverage = Account.PreciseLeverage;

StopOutLevel

Summary

Stop Out level is a lowest allowed Margin Level for account. If Margin Level is less than Stop Out, position will be closed sequentially until Margin Level is greater than Stop Out.

Signature

1
public abstract double StopOutLevel {get;}

Return Value

double

UserId

Summary

Gets the user ID.

Signature

1
public abstract long UserId {get;}

Return Value

long

Asset

Summary

Gets the account deposit asset/currency

Signature

1
public abstract Asset Asset {get;}

Return Value

Asset

TotalMarginCalculationType

Summary

Type of total margin requirements per Symbol.

Signature

1
public abstract TotalMarginCalculationType TotalMarginCalculationType {get;}

Return Value

TotalMarginCalculationType

Credit

Summary

Gets the credit of the current account.

Signature

1
public abstract double Credit {get;}

Return Value

double

UserNickName

Summary

Gets the user nick name.

Signature

1
public abstract string UserNickName {get;}

Return Value

string

CreationTime

Summary

Gets the account creation time.

Signature

1
public abstract DateTime CreationTime {get;}

Return Value

DateTime

Events

Switched

Summary

Occurs when user switch his account.

Signature

1
public abstract event Action<AccountSwitchedEventArgs> Switched;