ACTIV Field Types

The API exposes field data which is stored internally using a range of types. Where possible these have been mapped onto their JavaScript equivalents, as detailed in the enumeration documentation.

However, some types use bespoke implementations:

rational (represented by Rational) and tRational (represented by TRational)

Both types provide the ability to represent values with greater accuracy than the primitive number type allows, by storing an explicit numerator and denominatorType. In practice you'll normally encounter these types in fields containing monetary values.

If you wish to use a rational or tRational field type as a regular double-precision number, the API provides a doubleValue property. This property can be used explicitly or implicitly (valueOf() returns the doubleValue). (Note that in TypeScript, using the value implicitly may not always work. See here.)

Note that no arithmetic operations are supported on these types presently; they should be considered read-only.

Additionally, TRational contains trending information about how the value has changed since:

  • the previous disseminated value for the field that was different than the current value (via property trends.tick)
  • the previous day's value for the field (via property trends.onDay)
  • the previous disseminated value for the field (via property trends.onPrevious)

Note that, generally, trends.onPrevious dissemination is disabled for ACTIV ticker plants and will always be Trend.undefined. See here for further information.

Below is a short snippet showing how you can interact with the Rational and TRational types:

// NB Don't create these objects yourself, the API will create them for you.
const fieldOne = new activCgApi.Rational(10, activCgApi.DenominatorType.whole);

const currencyFormat = new Intl.NumberFormat(undefined, {
    currency: "USD",
    minimumFractionDigits: 2
});

console.log("Value", fieldOne.doubleValue);
console.log("Formatted value", currencyFormat.format(fieldOne.doubleValue));

const fieldTwo = new activCgApi.Rational(10, activCgApi.DenominatorType.whole);

console.log("Comparing referential equality", fieldOne === fieldTwo);
console.log("Comparing value equality", fieldOne.doubleValue === fieldTwo.doubleValue);
Try it out in the playground

time (represented by Time) and dateTime (represented by DateTime)

In order to support time fields with higher precision than milliseconds, the API provides a HighResDate type which extends the standard Date with microsecond and nanosecond precision. This type is used by the Time and DateTime field types.

These types should also be considered read-only; for example calling setMilliseconds() will not affect the value returned by getMicroseconds().

(Note: it is also used by the date field type such that the default toString() formatting is the same for date and dateTime fields, even though a field that only represents a date naturally has no micro- or nanoseconds).

Also in this Section