Pricing.Stream
Summary
Pricing.Stream objects are used for requesting, processing and managing a set of streaming level 1 (MarketPrice domain) quotes and trades.
The object automatically manages a set of streaming caches available for access at any time. Your application can then reach into this cache and pull out real-time fields by just calling a simple access method.
The object also emits a number of different events your application can listen to in order to be notified of the latest fields values in real-times.
Extends EventEmitter
.
Properties
definition: Pricing.Params
Actual params passed to Pricing.Definition
method.
Value: Prising.Param
session: Session
Returned value: actual session passed to getStream()
method.
state: State
Current state of the Pricing.Stream:
- State.Opened
- State.Pending
- State.Closed
Methods
open(params: Pricing.OpenStreamParams)
Allows you to open the Pricing connection by sending corresponding requests for all requested instruments.
It will be opened once all the requested instruments are received either a Refresh or a Status event.
Then the Pricing.Stream can be used in order to retrieve data.
Pricing.OpenStreamParams property:
Property | Is Optional | Default Value | Type | Description |
---|---|---|---|---|
withUpdates | Yes | true | boolean | If true - the streaming will work as usual and the data will be received continuously. If false only one data snapshot will be received (single Refresh - 'NonStreaming') and stream will be closed automatically |
Returned value: a Promise with the current pricing stream instance (this) Promise<Pricing.Stream>
.
close()
Allows you to closes the Pricing connection, releases resources.
Returned value: Promise<void>
.
getUniverse(): string[]
Allows you to get a list of the requested instrument names
Returned value: a list of the requested instrument names.
getFields(instrument: string, fields?: string[])
Allows you to get a list of the fields for a requested instrument
Parameters:
Name | Is Optional | Default Value | Type | Description |
---|---|---|---|---|
instrument | No | - | string | Name of the instrument (e.g. 'EUR=' ...) |
fields | Yes | - | string[] | Specifies the specific fields to be returned for the instrument. If it's not passed - all the fields for this instrument will be returned. |
Returned value:s a list of the requested fields for the instrument (OMMFields / undefined).
OMMFields description: Map contains any field name.
OMMFieldValue = type alias for the type string | number | null | boolean
{[field: string]: OMMFieldValue}
getFieldValue(instrument: string, field: string)
Allows you to get a list of the fields values for a requested instrument
Parameters:
Name | Is Optional | Default Value | Type | Description |
---|---|---|---|---|
instrument | No | - | string | Name of the instrument |
field | No | - | string | Name of the field you are interested in |
Returned value: a requested field value for the instrument (OMMFieldValue / undefined).
getItemStatus(instrument: string)
Parameters:
Name | Is Optional | Default Value | Type | Description |
---|---|---|---|---|
instrument | No | - | string | Name of the instrument |
Returned value: a state of the latest response for the instrument (OMMResponseState / undefined).
OMMResponseState interface description
Property | Is Optional | Default Value | Type | Description |
---|---|---|---|---|
Data | No | - | number/string | The data associated with the current stream state |
Stream | No | - | enum | Actual state of the stream. See OMMResponseStateType |
Code | Yes | - | number/string | Code of the stream status |
Text | Yes | - | string | Description of the stream state |
There are several additional methods to subscribe to Pricing.StreamEvent
They all are aliases for the .on()
method of the EventEmitter
interfaces.
See available events for the Pricing.Stream here.
-
onRefresh(cb: StreamRefreshCallback): Pricing.Stream
-
onUpdate(cb: StreamUpdateCallback): Pricing.Stream
-
onStatus(cb: StreamStatusCallback): Pricing.Stream
-
onComplete(cb: StreamCompleteCallback): Pricing.Stream
-
onError(cb: StreamErrorCallback): Pricing.Stream
Returned value: All of them return current instance of the Pricing.Stream, so you can chain them.
Examples of usage
close() example
pricingStream.close()
getUniverse() example
pricingStream.getUniverse();
getFields() example
const allEURFields = pricingStream.getFields('EUR=');
const subsetOfEURFields = pricingStream.getFields('EUR=', ['DSPLY_NAME', 'BID_NET_CH']);
getFieldValue() example
const fieldValue = pricingStream.getFieldValue('EUR=', 'DSPLY_NAME');
getItemStatus() example
const fieldValue = pricingStream.getItemStatus('EUR=');
methods of Pricing.StreamEvents
const stream = await pricingDefinition
.getStream(session)
.onRefresh(refreshCallback)
.onUpdate(refreshCallback)
.onStatus(statusCallback)
.onComplete(completeCallback)
.onError(errorCallback)
.open();