Type | Read/write | Author | Availability |
Write | FINBOURNE | Provided with LUSID |
Providing you have sufficient access control permissions, the Lusid.Allocation.Writer
provider enables you to write a Luminesce SQL query that either upserts or deletes allocations in LUSID.
Note: By default,
Lusid.Allocation.Writer
cannot add properties to allocations. To do this, you must first configureLusid.Allocation.Writer
to 'inline' properties. See how to do this.
You must construct a valid table of data to write, one allocation per record. Lusid.Allocation.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 allocation; that is, create an allocation if it does not exist, and update it if it does. This is the default operation if you omit
WriteAction
.Delete an allocation.
See also: Lusid.Allocation
Basic usage
@table_of_data = <select-statement>;
select * from Lusid.Allocation.Writer where toWrite = @table_of_data;
Query parameters
Lusid.Allocation.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.Allocation.Writer' and FieldType = 'Parameter';
Data fields
Lusid.Allocation.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 |
|
|
Delete |
|
|
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.Allocation.Writer' and FieldType = 'Column';
Write errors
We recommend examining the results of every write query using one or more of the WriteError
, WriteErrorCode
and WriteErrorDetail
fields.
For each record in the table of data to write, Lusid.Allocation.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 allocation
Upsert is the default operation if you omit the WriteAction
field.
@data_to_write = select 'Finbourne-Examples' as AllocationScope, 'ALLOCATION-1' as AllocationCode, 'Finbourne-Examples' as AllocatedOrderScope, 'ORDER-1' as AllocatedOrderCode,
'Finbourne-Examples' as PortfolioScope, 'UK-Equities' as PortfolioCode, 30 as Quantity, 60 as Price, 'LUID_ABCDEFGH' as LusidInstrumentId, 'Market' as Type, 'Buy' as Side,
#2024-06-01# as AllocationDate, 'Finbourne-Examples/PLACEMENT-1' as PlacementIds;
select * from Lusid.Allocation.Writer where ToWrite = @data_to_write;
Example 2: Create multiple allocations in the same scope
@@scope = select 'Finbourne-Examples';
@allocations = values
('ALLOCATION-A', 'ORDER-A', 'UK-Equities', 10, 95, 'LUID_00003DDL', 'Limit', 'Buy', 'Finbourne-Examples/PLACEMENT-A'),
('ALLOCATION-B', 'ORDER-B', 'UK-Equities', 30, 110, 'LUID_00003DCH', 'Limit', 'Buy', 'Finbourne-Examples/PLACEMENT-B'),
('ALLOCATION-C', 'ORDER-C', 'UK-Equities', 20, 40, 'LUID_ABCDEFGH', 'Market', 'Sell', 'Finbourne-Examples/PLACEMENT-C');
@data_to_write = select @@scope as AllocationScope, column1 as AllocationCode, @@scope as AllocatedOrderScope, column2 as AllocatedOrderCode, @@scope as PortfolioScope,
column3 as PortfolioCode, column4 as Quantity, column5 as Price, column6 as LusidInstrumentId, column7 as Type, column8 as Side, #2024-06-01# as AllocationDate,
column9 as PlacementIds from @allocations;
select * from Lusid.Allocation.Writer where ToWrite = @data_to_write;
Example 3: Delete an allocation
@data_to_write = select 'Finbourne-Examples' as AllocationScope, 'ALLOCATION-1' as AllocationCode, 'Delete' as WriteAction;
select * from Lusid.Allocation.Writer where ToWrite = @data_to_write;