Type | Read/write | Author | Availability |
Data provider | Write | Finbourne | Provided with LUSID |
The Lusid.Portfolio.Txn.Writer
provider enables you to write a Luminesce SQL query that either upserts or deletes transactions to or from one or more LUSID portfolios.
Note: The LUSID user running the query must have sufficient access control permissions to both use the provider and interact with transaction data in LUSID. This should automatically be the case if you are the domain owner.
You must construct a valid table of data to write, one transaction per record. Lusid.Portfolio.Txn.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 transaction; that is, create a transaction if it does not exist, and update it if it does. This is the default operation if you omit
WriteAction
. - Delete a transaction.
See also: Lusid.Portfolio.Txn
Basic usage
@table_of_data = <select-statement>; select * from Lusid.Portfolio.Txn.Writer where toWrite = @table_of_data;
Query parameters
Lusid.Portfolio.Txn.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.Portfolio.Txn.Writer' and FieldType = 'Parameter';
Data fields
Lusid.Portfolio.Txn.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 | Mandatory fields in table of data to write |
Upsert | PortfolioScope At least one instrument identifier, for example 'BBG00WGHTKZ0' as Figi |
Delete | PortfolioScope |
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.Portfolio.Txn.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.Portfolio.Txn.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.
For example, the query:
@table_of_data = select 'Finbourne-Examples' as PortfolioScope, 'UK-Equities' as PortfolioCode, 'Delete' as WriteAction; select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.Portfolio.Txn.Writer where toWrite = @table_of_data;
...fails because a TxnId
is not specified.
Examples
Note: For more example Luminesce SQL queries, visit our Github repo.
Example 1: Upsert a transaction in an equity to a portfolio
In this example, the instrument identifier is a non-currency LUID.
@table_of_data = select 'Finbourne-Examples' as PortfolioScope, 'UK-Equities' as PortfolioCode, 'txn-001' as TxnId, 'Buy' as Type, #2022-01-01# as TransactionDate, #2022-01-05# as SettlementDate, 100 as Units, 5 as TradePrice, 500 as TotalConsideration, 'GBP' as SettlementCurrency, 'LUID_ABCDEFGH' as LusidInstrumentId; select * from Lusid.Portfolio.Txn.Writer where ToWrite = @table_of_data;
Example 2: Upsert a transaction in a currency to a portfolio
In this example, the instrument identifier is a currency LUID.
@table_of_data = select 'Finbourne-Examples' as PortfolioScope, 'UK-Equities' as PortfolioCode, 'txn-002' as TxnId, 'FundsIn' as Type, #2022-01-01# as TransactionDate, #2022-01-01# as SettlementDate, 120000 as Units, 1 as TradePrice, 120000 as TotalConsideration, 'GBP' as SettlementCurrency, 'CCY_GBP' as LusidInstrumentId; select * from Lusid.Portfolio.Txn.Writer where ToWrite = @table_of_data;
Example 3: Upsert multiple transactions to multiple portfolios, and add properties
Note that to add or change transaction properties, Lusid.Portfolio.Txn.Writer
must have been configured to 'inline' the chosen properties (in this case BrokerCommission
) into the standard set of transaction fields.
@txns = values ('UK-Equities', 'txn-00001', 'Buy', 100, 250, 25000, 'TSCO', 'Tesco', 750), ('UK-Equities', 'txn-00002', 'StockIn', 100, 200, 20000, 'SBRY', 'Sainsburys', 600), ('Global-Equities', 'txn-00001', 'Sell', 100, 800, 80000, 'OCDO', 'Ocado', 2400); @table_of_data = select 'Finbourne-Examples' as PortfolioScope, column1 as PortfolioCode, column2 as TxnId, column3 as Type, #2022-01-01# as TransactionDate, #2022-01-05# as SettlementDate, column4 as Units, column5 as TradePrice, column6 as TotalConsideration, 'GBP' as SettlementCurrency, column7 as Ticker, column8 as ClientInternal, column9 as BrokerCommission from @txns; select * from Lusid.Portfolio.Txn.Writer where ToWrite = @table_of_data;
Example 4: Delete a transaction
@table_of_data = 'Finbourne-Examples' as PortfolioScope, 'UK-Equities' as PortfolioCode, 'UKEQTY100011' as TxnId, 'Delete' as WriteAction; select * from Lusid.Portfolio.Txn.Writer where ToWrite = @table_of_data;