Further Request Types

So far we have used the getEqual request method, since we knew beforehand the exact symbol we were interested in. However, other methods are available when this is not the case.

Note that the parameters for each request are largely the same; they all share the IRequestParameters interface. The difference between them is mainly what type of key is specified.

getMatch

This is very similar to a getEqual, except it can take a symbol (or symbols) without the trailing exchange code (e.g. MSFT, not MSFT.Q) and return either the composite record (MSFT.) or primary listing record (MSFT.Q).

// Initiate a getMatch request to the ContentGateway.
const requestHandle = client.streaming.getMatch({
    key: "MSFT",
    matchType: activCgApi.Streaming.GetMatchType.composite, // or GetMatchType.primary
    fieldIds: [activCgApi.FieldId.FID_BID, activCgApi.FieldId.FID_ASK]
});

This example will return MSFT. as we specified a composite lookup. It can be useful in interfaces where the user isn't (and shouldn't need to be) well versed in the ACTIV symbology.

getPattern

If we wanted to retrieve all the regional listing and composite records for Microsoft, we could use a getPattern request with a pattern of MSFT.*. Unlike getEqual and getMatch, pattern requests require a table number to be specified. Here's a working example to demonstrate:

// You may have to update the userId and password fields below.
const userId = "__ACTIV_FEED_USERNAME__";
const password = "__ACTIV_FEED_PASSWORD__";
const url = "ams://cg-ny4-replay.activfinancial.com/ContentGateway:Service";

(async function() {
    try {
        console.log("Connecting...");

        const client = await activCgApi.connect({
            url,
            userId,
            password
        });

        console.log("Connected. Initiating data request...");

        // Initiate a getPattern request to the ContentGateway.
        const requestHandle = client.streaming.getPattern({
            key: { symbol: "MSFT.*", tableNumber: activCgApi.TableNumber.usListing },
            fieldIds: [activCgApi.FieldId.FID_BID, activCgApi.FieldId.FID_ASK]
        });

        // Asynchronously iterate records.
        for await (const record of requestHandle) {
            console.log(`${record.responseKey.symbol} fields:`);

            // Synchronously iterate fields in the record.
            for (const field of record.fieldData) {
                console.log(`${activCgApi.FieldId[field.id]} = ${field.value}`);
            }

            console.log();
        }

        client.disconnect();
    } catch (e) {
        console.error(`Error: ${e}`);
    }
})();
Try it out in the playground

getPattern also supports a list of keys; e.g.

[
  { symbol: "MSFT.*", tableNumber: activCgApi.TableNumber.usListing },
  { symbol: "AAPL.*", tableNumber: activCgApi.TableNumber.usListing }
]

Additionally, if we asked for subscription with an update handler in the request parameters, any records that are added to the feed after the request completes will be provided to us in that handler; i.e. the subscription includes an implicit watch for new records matching the pattern.

getFirst, getLast

These requests will get the first or last N records in a specified table.

// Initiate a getFirst request to the ContentGateway.
// getLast would be similar.
const requestHandle = client.streaming.getFirst({
    key: activCgApi.TableNumber.usListing,
    numberOfRecords: 10,
    fieldIds: [activCgApi.FieldId.FID_BID, activCgApi.FieldId.FID_ASK]
});

getNext, getPrevious

These requests will get the next or previous N records before or after a specific symbol.

// Initiate a getNext request to the ContentGateway.
// getPrevious would be similar.
const requestHandle = client.streaming.getNext({
    key: { symbol: "MSFT.", tableNumber: activCgApi.TableNumber.usListing },
    numberOfRecords: 10,
    fieldIds: [activCgApi.FieldId.FID_BID, activCgApi.FieldId.FID_ASK]
});

Subscription filtering

Topics such as filtering subscriptions by event type (e.g. "give me only trades") and conflation ("give me all trades but conflate quotes with a 200ms period"), are covered here.

Also in this Section