Views:
TypeRead/writeAuthorAvailability
Data providerWriteFINBOURNEProvided with LUSID

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

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

You must construct a valid table of data to write, one order instruction per record. Lusid.OrderInstruction.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 an order instruction; that is, create an order instruction if it does not exist, and update it if it does. This is the default operation if you omit WriteAction
  • Delete an order instruction.

See also: Lusid.OrderInstruction

Basic usage

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

Query parameters

Lusid.OrderInstruction.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.OrderInstruction.Writer' and FieldType = 'Parameter';

Data fields

Lusid.OrderInstruction.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 fields
Upsert'Upsert' as WriteAction (or omit)OrderInstructionScope
OrderInstructionCode
Delete'Delete' as WriteActionOrderInstructionScope
OrderInstructionCode

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.OrderInstruction.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.OrderInstruction.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 instruction

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

@data_to_write = select 'Finbourne-Examples' as OrderInstructionScope, 'INSTRUCTION-1' as OrderCode, #2023-08-28# as CreatedDate, 12 as Quantity, 'LUID_ABCDEFGH' as LusidInstrumentId,
'Finbourne-Examples' as PortfolioScope, 'UK-Equities' as PortfolioCode;
select * from Lusid.OrderInstruction.Writer where ToWrite = @data_to_write;

Example 2: Create multiple order instructions in the same scope

@@scope = select 'Finbourne-Examples';
@@created = select #2023-08-28#;

@order_instructions = values
('INSTRUCTION-A', -10, 'LUID_00003DDL'),
('INSTRUCTION-B', 30, 'LUID_00003DCH'),
('INSTRUCTION-C', 10, 'LUID_ABCDEFGH');

@data_to_write = select @@scope as OrderInstructionScope, @@created as CreatedDate, column1 as OrderInstructionCode, column2 as Quantity, column3 as LusidInstrumentId from @order_instructions;
select * from Lusid.OrderInstruction.Writer where ToWrite = @data_to_write;

Example 3: Delete an order instruction

@data_to_write = select 'Finbourne-Examples' as OrderInstructionScope, 'INSTRUCTION-1' as OrderInstructionCode, 'Delete' as WriteAction;
select * from Lusid.OrderInstruction.Writer where ToWrite = @data_to_write;

Example 4: Create a rebalancing algorithm to generate order instructions from a portfolio valuation

You can create a custom view that can be used as a rebalancing algorithm to create new order instructions for various portfolios and valuation recipes on the fly. See this example for creating a rebalancing algorithm that sells out of all equity holdings under 1% of the exposure of a portfolio.