Lusid.Portfolio.Txn.Writer

Type

Read/write

Author

Availability

Data provider

Write

FINBOURNE

Provided with LUSID

Providing you have sufficient access control permissions, the Lusid.Portfolio.Txn.Writer provider enables you to write a Luminesce SQL query that either upserts or deletes transactions to or from transaction portfolios.

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

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 either of the following operations:

  • Upsert a transaction; that is, create a transaction if the TxnId is not yet registered with the portfolio, and update it if it is. More on this operation.

  • Delete (that is, cancel) a transaction. More on this operation.

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

Specify using...

Mandatory fields in table of data to write

Upsert

'Upsert' as WriteAction (or omit)

PortfolioScope

PortfolioCode

TxnId

Type

TransactionDate

SettlementDate

Units

TradePrice

TotalConsideration

SettlementCurrency
At least one instrument identifier, for example 'BBG00WGHTKZ0' as Figi

Delete

'Delete' as WriteAction

PortfolioScope

PortfolioCode

TxnId

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 WriteErrorWriteErrorCode 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 = select '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;