Type | Read/write | Author | Availability |
Data provider | Write | FINBOURNE | Provided with LUSID |
Providing you have sufficient access control permissions, the Lusid.Execution.Writer
provider enables you to write a Luminesce SQL query that either upserts or deletes executions in LUSID.
Note: By default, Lusid.Execution.Writer
cannot add properties to executions. To do this, you must first configure Lusid.Execution.Writer
to 'inline' properties. See how to do this.
You must construct a valid table of data to write, one execution per record. Lusid.Execution.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 execution; that is, create an execution in LUSID if it does not exist, and update it if it does. This is the default operation if you omit
WriteAction
. - Delete an execution.
See also: Lusid.Execution
Basic usage
@table_of_data = <select-statement>;
select * from Lusid.Execution.Writer where toWrite = @table_of_data;
Query parameters
Lusid.Execution.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.Execution.Writer' and FieldType = 'Parameter';
Data fields
Lusid.Execution.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) | ExecutionScope |
Delete | 'Delete' as WriteAction | ExecutionScope |
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.Execution.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.Execution.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 execution record
Upsert is the default operation if you omit the WriteAction
field.
@data_to_write = select 'Finbourne-Examples' as ExecutionScope, 'EXECUTION-1' as ExecutionCode, 'Finbourne-Examples' as RelatedPlacementScope, 'PLACEMENT-1' as RelatedPlacementCode, 'Filled' as State, 'Buy' as Side, 'Market' as Type, #2023-08-01# as CreatedDate, 'GBP' as Currency, 'GBP' as SettlementCurrency, 'Broker_A' as Counterparty, 50 as Quantity, 60 as AveragePrice, 'LUID_ABCDEFGH' as LusidInstrumentId; select * from Lusid.Execution.Writer where ToWrite = @data_to_write;
Example 2: Create multiple records of executions in the same scope
@@scope = select 'Finbourne-Examples'; @@created = select #2023-08-01#; @@currency = select 'GBP'; @executions = values ('EXECUTION-A', 'PLACEMENT-A', 'Filled', 'Buy', 'Limit', 'Broker_A', 40, 95, 'LUID_00003DDL'), ('EXECUTION-B1', 'PLACEMENT-B', 'Filled', 'Buy', 'Market', 'Broker_B', 44, 110, 'LUID_00003DCH'), ('EXECUTION-B2', 'PLACEMENT-B', 'Filled', 'Buy', 'Market', 'Broker_B', 20, 112, 'LUID_00003DCH'); @data_to_write = select @@scope as ExecutionScope, column1 as ExecutionCode, @@scope as RelatedPlacementScope, column2 as RelatedPlacementCode, column3 as State, column4 as Side, column5 as Type, @@created as CreatedDate, @@currency as Currency, @@currency as SettlementCurrency, column6 as Counterparty, column7 as Quantity, column8 as AveragePrice, column9 as LusidInstrumentId from @executions; select * from Lusid.Execution.Writer where ToWrite = @data_to_write;
Example 3: Delete an execution
@data_to_write = select 'Finbourne-Examples' as ExecutionScope, 'EXECUTION-1' as ExecutionCode, 'Delete' as WriteAction; select * from Lusid.Execution.Writer where ToWrite = @data_to_write;