Overview
This example demonstrates how to retrieve level 1 streaming data (such as trades and quotes) from the Refinitiv Data Platform. The example shows how to define a Pricing Stream object, which automatically manages a streaming cache available for access at any time.
Your application can then reach into this cache and pull-out real-time snapshots by just calling simple access methods. This example, calls the getFields()/getFieldValue() only once but it can do it anytime to retrieve the latest values received from the platform. So that, you can get the newest data about Euro for the named fields (DSPLY_NAME, PRCTCK_1,…) at any time (like 5 sec) after the stream has been opened. The Fields parameter is optional, if you do not call it, StreamingPrices will retrieve all fields and their values available for the requested instruments, in our case, for the EUR.
Example Code
const { ContainerSession, Pricing } = window['@refinitiv/dataplatform-containersession'];
const sxs = window.sxsWeb;
// For users, who use a private network
// sxs("config", "use-network", "private");
sxs.start(new Date());
sxs.onLoad(async () => {
console.log('[DEMO] WebSDK Loaded at time: ' + new Date());
const dataSession = ContainerSession.Definition({
appKey: 'InputAppKeyHere',
bus: sxs
}).getSession();
const pricingDefinition = Pricing.Definition({
universe: 'EUR=',
fields: ['DSPLY_NAME', 'PRCTCK_1', 'TRDPRC_1', 'PCTCHNG', 'HIGH_1', 'LOW_1']
});
const stream = pricingDefinition.getStream(dataSession);
dataSession
.open()
.then(() => stream.open())
.then(() => new Promise(res => setTimeout(res, 5000)))
.then(() => {
console.log(`EUR= all fields:`, stream.getFields('EUR='));
console.log(`EUR= subset of fields:`, stream.getFields('EUR=', ['DSPLY_NAME', 'BID_NET_CH']));
console.log(`EUR= field value of DSPLY_NAME field:`, stream.getFieldValue('EUR=', 'DSPLY_NAME'));
console.log(`EUR= stream status:`, stream.getItemStatus('EUR='));
console.log(`Stream instruments:`, stream.getUniverse());
return stream.close();
})
.catch(console.log)
.then(() => dataSession.close());
});
Example package
All our examples are available here for download