Views:
TypeRead/writeAuthorAvailability
Data providerWriteFinbourneProvided with LUSID

The Lusid.Instrument.Writer provider enables you to write a Luminesce SQL query to create, update or delete instruments of any asset class in LUSID.

Note: This provider does not create full economic definitions for instruments. While it may be useful for rapid prototyping, not all LUSID analytical functionality is subsequently available for these instruments. We recommend using dedicated writer providers for individual asset classes instead. More information.

If you do choose to use Lusid.Instrument.Writer, you must construct a valid table of data to write, one instrument per record. The provider lists the fields (columns) available to populate with values for each record, and has a set of parameters to help you construct a valid table.

Your query can use the WriteAction field to perform one of the following operations on the table of data to write:

  • Upsert an instrument; that is, update an existing instrument if a value for at least one unique identifier (such as a FIGI) already exists in LUSID, and create a new instrument if not. This is the default operation if you omit WriteAction. Note if you are creating an instrument, make sure to omit a value for the LusidInstrumentId field, since a unique LUID will be automatically created for you.
  • Hard or soft delete an instrument. For more information on the difference, see this article.

See also: Lusid.Instrument.<Type>.Writer providers

Basic usage

@table_of_data = <select-statement>;
select * from Lusid.Instrument.Writer where toWrite = @table_of_data;

Query parameters

The Lusid.Instrument.Writer provider has a set of parameters that help you construct a valid table of data to write.

Note: The toWrite parameter is mandatory and used to actually write the table of data into LUSID.

To list available parameters, their data types, default values, and an explanation for each, run the following query using a suitable tool (this example lists parameters for bonds, but they are the same for all providers):

select FieldName, DataType, ParamDefaultValue, Description from Sys.Field where TableName = 'Lusid.Instrument.Writer' and FieldType = 'Parameter';

Data fields

Lusid.Instrument.Writer lists the fields you can populate in your table of data to write.

Depending on the operation you want to perform, the following fields are mandatory to include in the table of data:

OperationSpecify using...Mandatory fieldsNotes
Upsert'Upsert' as WriteAction (or omit)

DisplayName
 

At least one unique identifier, for example 'BBG00WGHTKZ0' as Figi
 

If creating, do NOT specify LusidInstrumentId.
Delete'HardDelete' as WriteAction or 'SoftDelete' as WriteActionLusidInstrumentId 

To list all available fields for a particular provider, their data types, whether fields are considered 'main', and an explanation for each, run the following query using a suitable tool (this example lists fields for bonds):

select FieldName, DataType, IsMain, IsPrimaryKey, SampleValues, Description from Sys.Field where TableName = 'Lusid.Instrument.Writer' and FieldType = 'Column';

Write errors

We recommend examining the results of every write query using one or more of the WriteErrorWriteErrorCode and WriteErrorDetail fields.

For each record in the table of data to write, a Lusid.Instrument.Writer provider returns an error code. If an operation is successful, the error code is 0. If unsuccessful, a positive error code and explanation help you discover why LUSID considers the operation invalid.

Examples

Note: For more example Luminesce SQL queries, visit our Github repo.

Example 1: Create a new instrument

In this example, LUSID creates a new instrument providing a FIGI of BBG00WGHTKZ0 does not already exist in the instrument master.

Returning the LusidInstrumentId field is useful to reveal the unique LUID automatically generated for the new instrument.

@table_of_data = select 'AstraZeneca' as DisplayName, 'BBG00WGHTKZ0' as Figi;
select LusidInstrumentId, Figi, DisplayName, WriteErrorCode from Lusid.Instrument.Writer where toWrite = @table_of_data;

Example 2: Update an existing instrument

Following on from Example 1, since a FIGI of BBG00WGHTKZ0 now exists, the existing instrument is updated with a new display name.

Returning the LusidInstrumentId field again reveals the instrument has the same LUID, confirming no new instrument has been created.

@table_of_data = select 'AstraZeneca PLC' as DisplayName, 'BBG00WGHTKZ0' as Figi;
select LusidInstrumentId, Figi, DisplayName, WriteErrorCode from Lusid.Instrument.Writer where toWrite = @table_of_data;

Example 3: Delete an instrument in a particular scope

To delete an instrument, specify its LUID and either 'HardDelete' as WriteAction or 'SoftDelete' as WriteAction, for example:

@table_of_data = select 'LUID_00003DFA' as LusidInstrumentId, 'my-custom-instr-scope' as Scope, 'HardDelete' as WriteAction;
select * from Lusid.Instrument.Writer where toWrite = @table_of_data;