Lusid.Block.Writer

Type

Read/write

Author

Availability

Data provider

Write

FINBOURNE

Provided with LUSID

Providing you have sufficient access control permissions, the Lusid.Block.Writer provider enables you to write a Luminesce SQL query that either upserts or deletes order blocks in LUSID.

Note: By default, Lusid.Block.Writer cannot add properties to orders. To do this, you must first configure Lusid.Block.Writer to 'inline' properties. See how to do this.

You must construct a valid table of data to write, one order block per record. Lusid.Block.Writer 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:

  • Upsert a block; that is, create a block if it does not exist, and update it if it does. This is the default operation if you omit WriteAction

  • Delete a block.

See also: Lusid.Block

Basic usage

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

Query parameters

Lusid.Block.Writer has 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:

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

Data fields

Lusid.Block.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:

Operation

Specify using...

Mandatory fields

Upsert

'Upsert' as WriteAction (or omit)

BlockScope

BlockCode

Side

TimeInForce

Type

CreatedDate

Delete

'Delete' as WriteAction

BlockScope
BlockCode

To list all available fields, their data types, whether fields are considered 'main', and an explanation for each, run the following query using a suitable tool:

select FieldName, DataType, IsMain, IsPrimaryKey, SampleValues, Description from Sys.Field where TableName = 'Lusid.Block.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, Lusid.Block.Writer returns an error code. If the 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 an order block

Upsert is the default operation if you omit the WriteAction field.

@data_to_write = select 'Finbourne-Examples' as BlockScope, 'ORDER-1-BLK' as BlockCode, 'Buy' as Side, 100 as Quantity, 'LUID_ABCDEFGH' as LusidInstrumentId,
'Finbourne-Examples/ORDER-A, Finbourne-Examples/ORDER-B' as OrderIds, 'Market' as Type, 'GTC' as TimeInForce, #2024-01-31# as CreatedDate;
select * from Lusid.Block.Writer where ToWrite = @data_to_write;

Example 2: Create or update multiple blocks in the same scope

@@scope = select 'Finbourne-Examples';
@@created = select #2024-01-31#;

@blocks = values
('ORDER-1-BLK', 'Buy', 140, 'LUID_ABCDEFGH', 'Finbourne-Examples/ORDER-A, Finbourne-Examples/ORDER-B, Finbourne-Examples/ORDER-1', 'Market', 'GTC'),
('ORDER-B-BLK', 'Buy', 150, 'LUID_00003DCH', 'Finbourne-Examples/ORDER-C, Finbourne-Examples/ORDER-2', 'Market', 'GTC'),
('ORDER-C-BLK', 'Sell', 120, 'LUID_00003DDL', 'Finbourne-Examples/ORDER-D, Finbourne-Examples/ORDER-3', 'Market', 'GTC');

@data_to_write = select @@scope as BlockScope, column1 as BlockCode, column2 as Side, column3 as Quantity, column4 as LusidInstrumentId,
column5 as OrderIds, column6 as Type, column7 as TimeInForce, @@created as CreatedDate from @blocks;
select * from Lusid.Block.Writer where ToWrite = @data_to_write;

Example 3: Delete a block

@data_to_write = select 'Finbourne-Examples' as BlockScope, 'ORDER-1-BLK' as BlockCode, 'Delete' as WriteAction;
select * from Lusid.Block.Writer where ToWrite = @data_to_write;