|
| 1 | +// tslint:disable:no-console |
| 2 | +// tslint:disable-next-line: no-implicit-dependencies |
| 3 | + |
| 4 | +// ********************************************************************************************************************** |
| 5 | +// pricing-snapshot |
| 6 | +// The following example demonstrates a basic use case of the Pricing interface to retrieve a snapshot of prices from |
| 7 | +// the platform. The interface supports the ability to specify a list of items and the fields for each to retrieve. |
| 8 | +// |
| 9 | +// Note: To configure settings for your environment, modify the session.config json file |
| 10 | +// ********************************************************************************************************************** |
| 11 | + |
| 12 | +import { Pricing } from '@refinitiv-data/data'; |
| 13 | +import { getSession } from '../../Common/session'; |
| 14 | + |
| 15 | +const session = getSession(); |
| 16 | + |
| 17 | +(async () => { |
| 18 | + try { |
| 19 | + console.log('Opening the session...'); |
| 20 | + // open the session |
| 21 | + await session.open(); |
| 22 | + console.log('Session open, sending data request'); |
| 23 | + |
| 24 | + // specify a list of items and fields to retrieve a snapshot of prices |
| 25 | + const pricingDefinition = Pricing.Definition({ |
| 26 | + universe: ['EUR=', 'CAD=', 'GBP='], |
| 27 | + fields: ['DSPLY_NAME', 'BID', 'ASK', 'OPEN_PRC', 'PCTCHNG'], |
| 28 | + extendedParams: { |
| 29 | + QoS: { |
| 30 | + Rate: 'TimeConflated', |
| 31 | + RateInfo: 10000 |
| 32 | + } |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + const stream = pricingDefinition.getStream(session); |
| 37 | + // open the stream in snapshot mode |
| 38 | + await stream.open({withUpdates: false}); |
| 39 | + |
| 40 | + // print all the fields of one item |
| 41 | + console.log('\nEUR=, all fields: '); |
| 42 | + console.table(stream.getFields('EUR=')); |
| 43 | + |
| 44 | + // print one field |
| 45 | + console.log('\nCAD=, BID field value = ', stream.getFieldValue('CAD=', 'BID')); |
| 46 | + |
| 47 | + // print multiple fields |
| 48 | + console.log('\nGBP=, multiple fields value: '); |
| 49 | + console.table(stream.getFields('GBP=', ['DSPLY_NAME', 'BID', 'ASK'])); |
| 50 | + } |
| 51 | + catch (err) { |
| 52 | + console.log(err); |
| 53 | + } |
| 54 | + finally { |
| 55 | + await session.close(); |
| 56 | + } |
| 57 | +})(); |
0 commit comments