Time Series

In this tutorial we'll cover time series requests; their creation and parameters.

This section assumes a connection has been established; see the getting started tutorial as necessary.

Time series requests are used to retrieve data from the Time Series Server (TSS). The TSS stores quote and trade tick-by-tick data, builds intraday bars and stores historical daily data. Real-time data is ingested by the TSS which is immediately available for servicing requests.

Time series data is only available in environments that contain a TSS and requires users to be permissioned for access. Please contact your account manager for further details.

Data Ranges

All time series requests specify a data range in one of two ways.

  • Start date/time and end date/time

    • By default results are returned in chronological order (oldest first). The reverse option can be used to return results in the reverse order (most recent first).
    • Note that end must be later than start.
  • Start date/time and result count

    • Count indicates the maximum number of results to return.
    • A negative count will search backwards from the start date/time.
    • Results are returned in the order that the data is searched.

DateTime.MAX and DateTime.MIN can be used to specify the latest or earliest available data respectively.

History bars have a minimum resolution of days, so only the date parts are used for start and end parameters instead of date time.

Tick Requests

Tick requests retrieve intraday quote and trade tick data. Tick data is stored for a limited number of previous trading days.

/* global activOneApi */
// You may have to update the userId and password fields below.
const user = "__ACTIV_SESSION_USER_ID__";
const password = "__ACTIV_SESSION_PASSWORD__";
const host = "aop-ny4-replay.activfinancial.com";

(async function() {
    try {
        const session = await activOneApi.connect({
            host,
            user,
            password,
            onLogMessage(logType, message) {
                console.log(message);
            }
        });

        // Initiate a tick request for a days worth of ticks.
        session.timeSeriesTicks({
            dataSourceId: activOneApi.DataSourceId.activ,
            symbologyId: activOneApi.SymbologyId.native,
            symbol: "CSIQ.Q"
        },
        {
            start: activOneApi.DateTime.MAX,
            count: -20,
            filter: activOneApi.TickFilter.allTrades
        },
        {
            onTimeSeriesMessage (message) {
                console.log(`\nTick received for ${message.symbol}`);
        
                // Iterate through the fields in the response.
                for (const field of message.fieldData) {
                    let value = field.value;
                    if (field.id == activOneApi.FieldId.FID_TICK_TYPE)
                        value = activOneApi.TickType[value];
                    console.log(`${activOneApi.FieldId[field.id]}  =  ${value}`);
                }
            },
            onTimeSeriesFailure (message) {
                console.log(`Failure: ${activOneApi.StatusCode[message.statusCode]}`);
            }
        });
    } catch (e) {
        console.error(`Failure: ${activOneApi.StatusCode[e]}`);
    }
})();
Try it out in the playground

The data contained in the message can be accessed through the fieldData property. Details of how to use this can be found in the Field Data tutorial.

By default start and end times are requested in the local exchange timezone. The UTC option can be used to specify start/end in UTC.

Tick records can be filtered with record filters.

The FID_TICK_TYPE field indicates the type of tick. Values for this can be found in the TickType enumeration.

Quote Tick Data

  • TickType.BID (6)
  • TickType.ASK (7)
Field id Data type Description
FID_DATE_TIME DateTime Date/time of tick in the exchange timezone.
FID_TICK_TYPE number Type of tick record.
FID_UPDATE_ID number Internal update id.
FID_TICK_PRICE number Price of the quote event.
FID_TICK_SIZE number Size of the quote event.
FID_TICK_CONDITION string Condition data for the quote event.
FID_EXCHANGE string Exchange for the quote event, composite symbols only.

Trade Tick Data

  • TickType.TRADE (1)
  • TickType.TRADE_CORRECTION (2)
  • TickType.TRADE_CANCEL (3)
  • TickType.TRADE_NON_REGULAR (4)
  • TickType.FILTERED_TRADE (5)
Field id Data type Description
FID_DATE_TIME DateTime Date/time of tick in the exchange timezone.
FID_TICK_TYPE number Type of tick record.
FID_UPDATE_ID number Internal update id.
FID_TICK_PRICE number Price of the trade event.
FID_TICK_SIZE number Size of the trade event.
FID_TICK_CONDITION string Condition data for the trade event.
FID_EXCHANGE string Exchange for the trade event, composite symbols only.
FID_TRADE_BUYER_ID string Trade buyer id.
FID_TRADE_SELLER_ID string Trade seller id.
FID_TRADE_THROUGH_EXEMPT_FLAG string Trade through exempt flag.
FID_TRADE_ID string Trade id.

Trading Status Tick Data

  • TickType.TRADING_STATUS (12)
Field id Data type Description
FID_DATE_TIME DateTime Date/time of tick in the exchange timezone.
FID_TICK_TYPE number Type of tick record.
FID_UPDATE_ID number Internal update id.
FID_TRADING_STATUS string Trading status.
FID_TRADING_STATUS_REASON string Trading status reason.

Intraday Bar Requests

Intraday bar requests are used to get intraday data for a topic summarised over an interval specified in minutes. The currently supported bar intervals are 1, 2, 5, 10, 15, 30 and 60 minutes. Intraday bar data is stored for a limited number of previous trading days.

/* global activOneApi */
// You may have to update the userId and password fields below.
const user = "__ACTIV_SESSION_USER_ID__";
const password = "__ACTIV_SESSION_PASSWORD__";
const host = "aop-ny4-replay.activfinancial.com";

(async function() {
    try {
        const session = await activOneApi.connect({
            host,
            user,
            password,
            onLogMessage(logType, message) {
                console.log(message);
            }
        });

        // Initiate a intraday bar request.
        session.timeSeriesIntradayBars({
            dataSourceId: activOneApi.DataSourceId.activ,
            symbologyId: activOneApi.SymbologyId.native,
            symbol: "CSIQ.Q"
        },
        {
            start: new Date(new Date().toDateString() + " 00:00:00"),
            end: new Date(new Date().toDateString() + " 23:59:59"),
            barInterval: activOneApi.IntradayInterval.thirtyMinute
        },
        {
            onTimeSeriesMessage (message) {
                console.log(`\nIntraday bar received for ${message.symbol}`);
        
                // Iterate through the fields in the response.
                for (const field of message.fieldData) {
                    console.log(`${activOneApi.FieldId[field.id]}  =  ${field.value}`);
                }
            },
            onTimeSeriesFailure (message) {
                console.log(`Failure: ${activOneApi.StatusCode[message.statusCode]}`);
            }
        });
    } catch (e) {
        console.error(`Failure: ${activOneApi.StatusCode[e]}`);
    }
})();
Try it out in the playground

The data contained in the message can be accessed through the fieldData property. Details of how to use this can be found in the Field Data tutorial.

By default start and end times are requested in the local exchange timezone. The UTC option can be used to specify start/end in UTC.

Intraday records can be filtered with record filters.

Intraday Bar Data

Field id Data type Description
FID_DATE_TIME DateTime Start date/time of the bar in the exchange timezone.
FID_OPEN number Opening price for the period.
FID_TRADE_HIGH number Highest price for the period.
FID_TRADE_LOW number Lowest price for the period.
FID_CLOSE number Closing price for the period.
FID_CUMULATIVE_VOLUME number Cumulative volume for the period.
FID_CUMULATIVE_PRICE number Cumulative price for the period.
FID_CUMULATIVE_VALUE number Cumulative value for the period.
FID_TICK_COUNT number Number of ticks for the period.
FID_ALTERNATIVE_CUMULATIVE_VOLUME number Cumulative volume for the period excluding trades with no price.
FID_INTRADAY_BAR_FLAGS number Flags for the period, see Intraday bar flags

History Bar Requests

History bar requests are used to get historical data for a topic summarised over an interval specified in days. The currently supported bar intervals are daily, weekly and monthly. History bar data is stored indefinitely.

/* global activOneApi */
// You may have to update the userId and password fields below.
const user = "__ACTIV_SESSION_USER_ID__";
const password = "__ACTIV_SESSION_PASSWORD__";
const host = "aop-ny4-replay.activfinancial.com";

(async function() {
    try {
        const session = await activOneApi.connect({
            host,
            user,
            password,
            onLogMessage(logType, message) {
                console.log(message);
            }
        });

        // Get the date from a month ago for the data start.
        const startDate = new Date();
        startDate.setMonth(startDate.getMonth() - 1);

        // Initiate a history bar request.
        session.timeSeriesHistoryBars({
            dataSourceId: activOneApi.DataSourceId.activ,
            symbologyId: activOneApi.SymbologyId.native,
            symbol: "CSIQ.Q"
        },
        {
            start: startDate,
            end: activOneApi.Date.MAX,
            barInterval: activOneApi.HistoryInterval.daily
        },
        {
            onTimeSeriesMessage (message) {
                console.log(`\nHistory bar received for ${message.symbol}`);
        
                // Iterate through the fields in the response.
                for (const field of message.fieldData) {
                    console.log(`${activOneApi.FieldId[field.id]}  =  ${field.value}`);
                }
            },
            onTimeSeriesFailure (message) {
                console.log(`Failure: ${activOneApi.StatusCode[message.statusCode]}`);
            }
        });
    } catch (e) {
        console.error(`Failure: ${activOneApi.StatusCode[e]}`);
    }
})();
Try it out in the playground

The data contained in the message can be accessed through the fieldData property. Details of how to use this can be found in the Field Data tutorial.

History Bar Data

Field id Data type Description
FID_DATE_TIME DateTime Start date/time of the bar in the exchange timezone.
FID_OPEN number Opening price for the period.
FID_TRADE_HIGH number Highest price for the period.
FID_TRADE_LOW number Lowest price for the period.
FID_CLOSE number Closing price for the period.
FID_CUMULATIVE_VOLUME number Cumulative volume for the period.
FID_CUMULATIVE_PRICE number Cumulative price for the period.
FID_CUMULATIVE_VALUE number Cumulative value for the period.
FID_TICK_COUNT number Number of ticks for the period.
FID_OPEN_INTEREST number Open interest for the period.

Processing Results

The results of a time series request are notified via the callback handler provided when the data was requested. The interface provides the following callbacks:

  • Message (requested data)
  • Failure (notification of a failure)

The data contained in the message can be accessed through the fieldData property. Details of how to use this can be found in the Field Data tutorial.

For a success, or failure for a specific topic, the symbol will be provided with the result message. For a general failure of the overall request (e.g. a request where no data is available) the symbol will be empty.

If the request fails a StatusCode will indicate the cause of the failure.

Time series Handle

The TimeSeriesHandle can also be used to process results of the requests. The handle can be async iterated through as an async collection of TimeSeriesResult objects. A time series result contains a statusCode property that indicates if there has been an error. If the status code is StatusCode.success then the message property will also be defined and contain a part of the requested data.

Also in this Section