Views:
TypeRead/writeAuthorAvailability
Data providerWriteFINBOURNEProvided with LUSID

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

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

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

See also: Lusid.PortfolioOrder

Basic usage

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

Query parameters

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

Data fields

Lusid.PortfolioOrder.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)OrderScope
OrderCode
Side
Delete'Delete' as WriteActionOrderScope
OrderCode

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.PortfolioOrder.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.PortfolioOrder.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

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

@data_to_write = select 'Finbourne-Examples' as OrderScope, 'ORDER-1' as OrderCode, 'Buy' as Side, 50 as Quantity, 'LUID_ABCDEFGH' as LusidInstrumentId,
'Finbourne-Examples' as PortfolioScope, 'UK-Equities' as PortfolioCode;
select * from Lusid.PortfolioOrder.Writer where ToWrite = @data_to_write;

Example 2: Create multiple orders in the same scope

@@scope = select 'Finbourne-Examples';

@orders = values
('ORDER-A', 'Buy', 10, 'LUID_00003DDL'),
('ORDER-B', 'Buy', 50, 'LUID_00003DCH'),
('ORDER-C', 'Sell', 20, 'LUID_ABCDEFGH');

@data_to_write = select @@scope as OrderScope, column1 as OrderCode, column2 as Side, column3 as Quantity, column4 as LusidInstrumentId,
'Finbourne-Examples' as PortfolioScope, 'UK-Equities' as PortfolioCode from @orders;
select * from Lusid.PortfolioOrder.Writer where ToWrite = @data_to_write;

Example 3: Delete an order

@data_to_write = select 'Finbourne-Examples' as OrderScope, 'ORDER-1' as OrderCode, 'Delete' as WriteAction;
select * from Lusid.PortfolioOrder.Writer where ToWrite = @data_to_write;