Access to symbol/account additional fields
Access to collection of additional fields

Theory

Quantower terminal contains lot of useful panels. There are complex panels that display data and allow you to manipulate it. But also, there are simple panels that simply display data. For example, Symbol Info and Account info panels. Their goal is to provide all available information on the selected symbol and account.
The Quantower API divides the information they display into two categories - basic information and additional information.

Basic information

The basic information includes fields without which the selected object cannot exist. For successfull integration with Quntower each broker must provide these fields. For example, each symbol must have Id, Name, Tick size, Product/Quoting currencies, Min lot etc. Also each account must have Id, Name, Balance, Asset etc.
Quantower API supports Symbol and Account classes and you can get all the basic information using their properties members.

Additional information

The additional information includes fields which are specific for selected broker/data feed. At any time, the broker can stop sending these fields, and if it happens, you can continue to use this connection without any problems. For examle, Bybit crypto-connection provides for each symbols Maker and Taker fees fields.
Since these fields may be unique to concrete broker, we don’t add new properties to our objects, but we store them in a special collection.
Each Account and Symbol object contains an AdditionalInfo collection, which stores instances of the AdditionalInfoItem class. Let's take a look at the main properties of this class.
    Id - unique identifier
    NameKey - display name
    Value - value of this field
    DataType - enum, defines value type (Int, String, Double etc.)
    GroupInfo - name of group
    Visible - if true, it can be displayed in plugins
So, If you find required field in Symbol Info panel and you want to use it in your code:
    1.
    Try to find the corresponding property
    2.
    Try to find the corresponding AdditionalInfoItem element in AdditionalInfo collection.

Practice

In this part of acticle we will create a strategy script which will show all additional fields of selected symbol and account. As example we will use cTrader connection.

Input parameters

First, let’s define input parameters. We want to customize symbol and account
1
[InputParameter("Selected account", 10)]
2
public Account account;
3
4
[InputParameter("Selected symbol", 20)]
5
public Symbol symbol;
Copied!

OnRun method

Here we check the input parameters and display the elements of the AdditionalInfo collections.
1
protected override void OnRun()
2
{
3
//
4
// check if account is null
5
//
6
if (this.account == null)
7
{
8
this.Log("Account is null", StrategyLoggingLevel.Error);
9
this.Stop();
10
return;
11
}
12
13
//
14
// check if symbol is null
15
//
16
if (this.symbol == null)
17
{
18
this.Log("Symbol is null", StrategyLoggingLevel.Error);
19
this.Stop();
20
return;
21
}
22
23
Log("=========================================", StrategyLoggingLevel.Trading);
24
25
//
26
// check if account contains additional fields
27
//
28
if (this.account.AdditionalInfo != null && this.account.AdditionalInfo.Count > 0)
29
{
30
foreach (var accountAddtionalItem in this.account.AdditionalInfo)
31
Log(quot;{accountAddtionalItem.NameKey}: {accountAddtionalItem.Value}", StrategyLoggingLevel.Info);
32
}
33
34
Log("========== Account additional fields ==========", StrategyLoggingLevel.Trading);
35
36
//
37
// check if symbol contains additional fields
38
//
39
if (this.symbol.AdditionalInfo != null && this.symbol.AdditionalInfo.Count > 0)
40
{
41
foreach (var symbolAdditionalItem in this.symbol.AdditionalInfo)
42
Log(quot;{symbolAdditionalItem.NameKey}: {symbolAdditionalItem.Value}", StrategyLoggingLevel.Info);
43
}
44
45
Log("========== Symbol additional fields ===========", StrategyLoggingLevel.Trading);
46
}
Copied!

OnGetMetrics method

In metrics, let's output one additional field for each input objects. But, here we have a problem. Well, if we want to get concrete element form AdditionalInfo collection we need to know its correct identifier.
At this moment, the easiest way to do this:
    1.
    Run script in Debug-mode and find the required element in AdditionalInfo collection.
    2.
    Store identifier(Id property) of this element as a constant.
    3.
    Use 'TryGetItem' method with stored identifier to get required element.
Ok, let's find 'Broker' and 'Swap short' elements in AdditionalInfo collections.
Pay attention. These elements are provided by cTrader connection. Another words, we will find them only if we will use symbol and account from cTrader connection as script input parameters.
We found them. Now we need save this identifiers as string constants.
1
private const string CTRADER_SWAP_SHORT_SYMBOL_ADDITIONAL_FIELD_ID = "Swap short";
2
private const string CTRADER_BROKER_ACCOUNT_ADDITIONAL_FIELD_ID = "Broker";
Copied!
Done. Now we can add needed metrics.
1
protected override List<StrategyMetric> OnGetMetrics()
2
{
3
var result = base.OnGetMetrics();
4
5
if (symbol != null && symbol.AdditionalInfo.TryGetItem(CTRADER_SWAP_SHORT_SYMBOL_ADDITIONAL_FIELD_ID, out var accAdditionalItem))
6
{
7
result.Add(new StrategyMetric()
8
{
9
Name = accAdditionalItem.NameKey,
10
FormattedValue = accAdditionalItem.Value.ToString()
11
});
12
}
13
14
if (account != null && account.AdditionalInfo.TryGetItem(CTRADER_BROKER_ACCOUNT_ADDITIONAL_FIELD_ID, out var symbolAdditionalItem))
15
{
16
result.Add(new StrategyMetric()
17
{
18
Name = symbolAdditionalItem.NameKey,
19
FormattedValue = symbolAdditionalItem.Value.ToString()
20
});
21
}
22
23
return result;
24
}
Copied!
Last modified 6mo ago