Chain
Summary
Chain content object gives your application an easy access to Chain Data.
Example of usage
import { Pricing } from '@refinitiv-data/data';
const session = /* session creation is omitted */
(async () => {
try {
await session.open();
const chainRecordName = '.AV.HSI'
const chainDefinition1 = Pricing.Chain.Definition(chainRecordName);
const chainDefinition2 = Pricing.Chain.Definition({
name: chainRecordName,
skipEmpty: true,
nameGuessingQuantity: 8
});
const streamChain1 = await chainDefinition1.getStream(session, 'pricing/main') // second parameter 'api' is optional
.onAdd((constituent: string, index: number, sc: Pricing.Chain.StreamingChain): void => console.log(`${index}:${constituent}`)) // when the new element is added to constituents list
.onRemove((constituent: string, index: number, sc: Pricing.Chain.StreamingChain) => console.log(`${index}:${constituent}`))
.onUpdate((newConstituent: string, oldConstituent: string, index: number, sc: Pricing.Chain.StreamingChain) => console.log(`${index}:${oldConstituent}:${newConstituent}`))
.onComplete((constituents: string[], sc: Pricing.Chain.StreamingChain) => console.log(constituents)) // when chain decoding is completed, all constituents are passed as param
.onError((err: Error, sc: Pricing.Chain.StreamingChain) => console.log('error', err))
.open();
const streamChain2 = await chainDefinition2.getStream(session)
.on(Pricing.Chain.Event.Add, (constituent: string, index: number, sc: Pricing.Chain.StreamingChain) => console.log(`${index}:${constituent}`))
.on(Pricing.Chain.Event.Remove, (constituent: string, index: number, sc: Pricing.Chain.StreamingChain) => console.log(`${index}:${constituent}`))
.on(Pricing.Chain.Event.Update, (newConstituent: string, oldConstituent: string, index: number, sc: Pricing.Chain.StreamingChain) => console.log(`${index}:${oldConstituent}:${newConstituent}`))
.on(Pricing.Chain.Event.Complete, (constituents: string[], sc: Pricing.Chain.StreamingChain) => console.log(constituents))
.on(Pricing.Chain.Event.Error, (err: Error, sc: Pricing.Chain.StreamingChain) => console.log('error', err))
.open();
console.log(streamChain1.getConstituents()); // returns all constituents
console.log(streamChain1.isChain); // this prop returns true if decoding is completed, otherwise false
console.log(streamChain1.summaryLinks); // returns a list of the summary links of the chain record
console.log('streamChain2.isChain(): ', streamChain2.isChain); // returns a list of the summary links of the chain record
await streamChain1.close();
await streamChain2.close();
} catch (err) {
console.error(err);
} finally {
session.close();
}
})();