Skip to main content
Version: latest

Value formatters

You can determine how the values appear in the Account Manager tables by using the formatter property of AccountManagerColumnBase. If no formatter is set, values are displayed as they are, separated by spaces. When a formatter is defined, it processes only the values specified in the dataFields property. If dataFields is an empty array, the formatter will receive the entire order/position data object.

// AccountManagerColumnBase object
{
id: "limitPrice",
label: "Limit Price",
dataFields: ["limitPrice"],
formatter: "formatPrice", // Standard formatter that displays symbol's price
},

The formatter property can contain either StandardFormatterName or FormatterName object.

Formatter and dataFields dependency

The formatter property expects that the dataFields property has certain types of values defined in a specific order. dataFields is an array of strings that match the property names in the order/position data object. The values for these properties in the data object are expected to be a number, string, date, etc. The mapping of the formatter and dataFields values is described in the StandardFormattersDependenciesMapping interface.

Example

Assume that your data object has two custom fields: balance and currency.

{
// <...other object fields...>
balance: 1000.00,
currency: "EUR",
}

You want to display the user's balance in a column. The balance value should have two decimal places and a currency symbol. For this purpose, you can use the built-in fixedInCurrency formatter that expects the following arguments:

  1. A number that represents the price.
  2. A string that represents the currency code.

This means that dataFields should have the values of the followings types: [number, string]. Then, the AccountManagerColumnBase object for the balance column should look as follows:

{
id: "balance",
label: "Balance",
dataFields: ["balance", "currency"],
formatter: "fixedInCurrency",
},

Built-in formatters

The table below lists the built-in formatter values, expected types of the properties within dataFields, and the default fields of the order/position data object.

NameValueDescription
#
"date"
#
"dateOrDateTime"
#
"default"
#
"empty"
#
"fixed"
#
"fixedInCurrency"
#
"formatPrice"
#
"formatPriceForexSup"
#
"formatQuantity"
#
"integerSeparated"
#
"localDate"
#
"localDateOrDateTime"
#
"marginPercent"
#
"percentage"
#
"pips"
#
"positionSide"
#
"profit"
#
"profitInInstrumentCurrency"
#
"side"
#
"status"
#
"symbol"
#
"text"
#
"type"
#
"variablePrecision"

Custom formatters

You can implement your custom formatter using the customFormatters property in the AccountManagerInfo object. Each custom formatter is an object with the following fields.

PropertyRequiredDescription
name
#
formatText
#
formatElement
#
isPriceFormatterNeeded
#

Example

The CodePen example below implements two custom formatters that display the following:

  • Dynamically changing text
  • A button

These formatters are used to format values for custom columns of the Positions page.