Field Data

In this tutorial we will describe how to use FieldData that is found in SnapshotMessages and SubscriptionMessages.

This section assumes a connection has been established; see the getting started tutorial as necessary. This tutorial also assumes we have a message from either a snapshot or susbcription.

The FieldData is only valid while the message is also valid i.e. delete hasn't been called on the message either by calling delete explicitly or implicitly by iterating to the next message - see Snapshot and Subscription tutorials for details.

Fields

FieldData is a collection of Field items that can either be iterated through. Here we have an example of iterating through all fields in a message and logging the id of the field and the value:

for (const field in message.fieldData) {
    console.log(`${activOneApi.FieldId[field.id]}  =  ` + (field.isDefined ? field.value : "[undefined]"));
}

Each field can also be accessed directly using a known id, for example from the market data FieldId or the PlatformFieldId enumerations depending on the data source. Here we have an example of checking the existance of the bid and ask fields from a message and logging the fields if they exist:

console.log("FID_BID:");
if (message.fieldData.isFieldPresent(activOneApi.FieldId.FID_BID)) {
    console.log(message.fieldData.getField(activOneApi.FieldId.FID_BID));
} else {
    console.log("[Not present]");
}
console.log("FID_ASK:");
if (message.fieldData.isFieldPresent(activOneApi.FieldId.FID_ASK)) {
    console.log(message.fieldData.getField(activOneApi.FieldId.FID_ASK));
} else {
    console.log("[Not present]");
}

Each field has a property isDefined that indicates whether the field has a value. Every defined field has a type and a value, for more details on what these contain see the FieldType enumeration documentation and the ACTIV field types tutorial.

Each field also has a property doesUpdateLastValue, that indicates whether the value should be used to update any cached value. For a last value cache, if this is false the field value should not replace any stored value. For example, in terms of market data, this would be present on the trade price for a non-regular trade event.

Also in this Section