Getting started
Concepts
- Model concepts
- API concepts
- API versions
- Entitlements
- Filters
- Request parameters
- Usage quota
- Error codes
Services
Parameters
- after
- aggregate
- aggregateIncrementFrom
- cursor
- dateFormat
- descending
- entity
- envelope
- fields
- format
- from
- groupBy
- groupById
- groupByIdAndTime
- groupByTo
- includeMetaData
- inline
- inlineLatest
- inlineTimeseries
- limit
- modulus
- nextUrl
- part
- pivot
- rankBy
- requestTimeout
- returnPreSignedUrl
- showMessage
- showStreamCursor
- to
- trace
- verifyLinks
- wait
Deprecated parameters
Datasets
- ECR: timeseries and observations
- ECR: usage patterns
- fiindices: retrieving index data
- Parsing: asset classes
- Parsing: best practices
Samples
stream
The stream service returns the updates flowing through the platform, one message at a time, in the order in which they were published. Use it to keep a local copy of the data up to date.
To stream the updates of all entities in the namespace:
https://consumer.qa.data.spglobal.com/namespace/stream?...To stream the updates of one entity only:
https://consumer.qa.data.spglobal.com/namespace/Entity/stream?...
Message structure
Every response is a JSON document, a stream message, similar to this UPDATE message:
{
"cursor": 12125764,
"at": "2017-01-01T00:00:00Z",
"messageType": "UPDATE",
"entityType": "Entity",
"data": [...],
"publishRequestId": "X0.1606987416.1",
"timeToFirstWrite": 1,
"after": "12125764,123"
}
| Field | Description |
|---|---|
cursor | The position of the message in the stream. The cursor increases with each message but the values are not consecutive. The cursor applies to the whole namespace, so the cursors of /namespace/Entity/stream are a subset of those of /namespace/stream. |
at | The time the message entered the stream. This is a technical field without business meaning. |
messageType | The type of message. See below. |
entityType | The entity the message applies to. |
receivedSequence | For datasets published in batches: the position at which the message was received. The cursor is then the position at which it was committed. |
mode | The publication mode of the message, for example NORMAL or BACKFILL. |
publishRequestId | The identifier of the publication that produced the message. |
batchRunId | For messages with records: the batch run that published them, for datasets published in batches. |
timeToFirstWrite | The time in milliseconds the server needed before it started to send the response. |
after | The value to use for the after parameter of the next request. |
Important: The structure of messages evolves. New fields and new message types can be added at any time. A client must ignore fields it does not know, and must log and skip message types it does not know instead of failing.
Message types
| Message type | Description |
|---|---|
UPDATE | New or updated instances, in the data array. |
DELETE | The instances with the identifiers in ids were deleted. When from, to and datetimeField are present, only the records within that time range of the field datetimeField are deleted. Otherwise all records of the entity with these ids are deleted. |
BULK_UPDATE | A change that was applied to many records at once (for datasets running in extended mode). Only returned with messageType=BULK_UPDATE. data is a list of objects with filter (the fields and values of the records that are changed), update (the new values), applyOnTimeseries and applyOnSnapshot. |
DELETE_BY_KEY, RETENTION_DELETE | Records that were deleted by key or removed by the retention policy. As UPDATE, data holds the deleted records. |
PURGE | Data was removed completely from the platform, including from the stream. The from and to range and a filters list of filterField and filterValue pairs can describe which data. The identifiers of the removed records are not provided. |
DICTIONARY_UPDATE | The data dictionary of the namespace changed, potentially adding fields or entities. data has the new version of the dictionary. |
BATCH_RUN_EVENT | Marks the start, the end or the cancellation of a batch run, with the fields eventType (START, END or CANCEL), batchId, batchRunId, asOf, recordCount and mode. In API version 2 the message types are BATCHRUN_START, BATCHRUN_COMPLETE and BATCHRUN_CANCEL. See API versions. |
CLEAR_DATA | The API drops the data of the entity. |
REFRESH_CACHE | The API refreshes its caches. |
EMPTY | A message without data. See below. |
Examples of the other messages:
{
"cursor": 89589,
"at": "2017-01-01T00:00:00Z",
"messageType": "DELETE",
"entityType": "Entity",
"ids": ["012345678911"],
"from": "2017-01-01T23:00:00Z",
"to": "2017-01-02T23:00:00Z",
"datetimeField": "asOfDateTime",
"publishRequestId": "X0.1606987416.1",
"timeToFirstWrite": 1,
"after": "89589"
}
{
"cursor": 19101427,
"at": "2017-06-29T08:27:09.991Z",
"messageType": "EMPTY",
"timeToFirstWrite": 1,
"after": "19101427"
}
EMPTY messages
In API version 2 an EMPTY message has no messageType and no at field. An EMPTY message is returned in two situations:
- The end of the stream is reached and there are no new updates. The
aftervalue equals theaftervalue of the request. - No message matching your request and entitlements was found within a reasonable time. The
aftervalue differs from the request and marks how far the server has searched.
In both cases the correct response is to request the next message immediately with the returned after value. When nothing could be scanned at all, for example on an empty stream or when no message matches from and to, after is -1. Never use -1 in a request; check your parameters or timing instead.
Reading the stream
On every call after the first, set after to the after value of the previous response:
https://consumer.qa.data.spglobal.com/namespace/stream?after=AFTER_VALUE
Important: Request the next message immediately after you receive a response. Process the message in another thread so that processing does not delay polling.
Where to start is selected with the first request:
| Request | Result |
|---|---|
after=AFTER_VALUE | The message after that position. If there is none, an EMPTY message with the same after value. |
after=head | An EMPTY message whose after value is the current end of the stream. Reading from there returns only new messages. |
after=scan | The most recent message that contains data. If none is found within a certain period, an EMPTY message. |
from=DATE without after | The first message published at or after that date and time, followed by all later messages. |
| neither | The default of your account, normally the same as after=head. |
from and to refer to the time at which a message was published, not to a date field in the data.
Limiting the size of a response
limit restricts the number of records in a response. When an UPDATE message holds 1000 records and the limit is 200, the message is delivered in five responses. The after value of each response selects the next part, in the form cursor,index. The limit can be at most 10,000.
Combining messages
With aggregate=true and a limit up to 10,000, one response contains the data of several messages, which reduces the effect of network latency on streams with a high update rate. The response then has a messages array instead of data, and aggregated is true:
.../stream?aggregate=true&limit=10000
Filtering the stream
The stream can be filtered on properties of the message. These filters are indexed and can reduce the volume of the stream considerably.
| Parameter | Description |
|---|---|
messageType | Only messages of this type. Use the names of API version 2 as listed in API versions, such as UPDATE, DELETE, BULK_UPDATE and BATCHRUN_COMPLETE. EMPTY and BATCH_RUN_EVENT are not accepted. |
mode | Only messages with this publication mode, for example NORMAL, BACKFILL, RESTATEMENT or ADJUSTMENT. |
batchRun | Only messages of this batch run. |
receivedSequence | Only messages with this received sequence. This links records from the latest and timeseries services (with showMessage) to the stream. |
| entity | On the stream of a namespace: only these entities. |
Entity.field | On the stream of a namespace: only records of the entity with this value of the field, for example Price.isin=US0378331005. Messages that carry no records, such as DELETE, are not returned when you use these filters. |
id and other filters | On the stream of an entity: only the records that match. Messages without matching records are returned as EMPTY. |
| fields | Restricts the fields in data. |
| returnPreSignedUrl | Replaces attachment ids by download URLs. |
Waiting for new messages
Use wait to have the server hold a request at the end of the stream until a message arrives or the time is over. The default is 1000 ms and the maximum is 300,000 ms.
Retrieving a single message
cursor returns one specific message again.