Views:
TypeRead/writeAuthorAvailability
Data providerWriteFINBOURNEProvided with LUSID

Providing you have sufficient access control permissions, the Lusid.FeeRule.Writer provider enables you to write a Luminesce SQL query that either upserts or deletes fee and commission rules in LUSID.

Note: By default, Lusid.FeeRule.Writer cannot attach fee rules to transaction property keys that do not yet exist. To do this, you must first create a transaction property key which you can add a fee rule to. See how to do this.

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

See also: Lusid.FeeRule

Basic usage

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

Query parameters

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

Data fields

Lusid.FeeRule.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)Code
TransactionPropertyKey
Country
Exchange
Custodian
Counterparty
ExecutionBroker
Description
TransactionType
SettlementCurrency
TransactionCurrency
Delete'Delete' as WriteActionCode

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.FeeRule.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.FeeRule.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: Add a fee rule to an existing transaction property key

Upsert is the default operation if you omit the WriteAction field. Specifying a value of * for Country, Exchange, Custodian, Counterparty, ExecutionBroker, TransactionType, SettlementCurrency or TransactionCurrency ensures the fee rule is applied to a transaction for any value in that field. For example, the following fee rule is applied to all transaction types executed by Broker A:

@data_to_write = select 'FeeRule-123' as Code, 'Transaction/Fee/BrokerA' as TransactionPropertyKey, 'UK' as Country, '*' as Exchange, '*' as Custodian,
'BrokerA' as Counterparty, 'BrokerA' as ExecutionBroker, 'Fee rule for Broker A' as Description, '*' as TransactionType, 'GBP' as SettlementCurrency, 'GBP' as TransactionCurrency;
select * from Lusid.FeeRule.Writer where ToWrite = @data_to_write;

Example 2: Create multiple fee rules at once

In this example, multiple fee rules are upserted to existing properties in one call.

@rules = values
('FeeRule-C', 'Transaction/Fee/BrokerA', 'UK', '*', '*', 'BrokerA', 'BrokerA', 'Fee for buying with Broker A', 'Buy', 'GBP'),
('FeeRule-D', 'Transaction/Commission/BrokerA', 'UK', '*', '*', 'BrokerA', 'BrokerA', 'Commission for selling with Broker A', 'Sell', 'GBP'),
('FeeRule-E', 'Transaction/Fee/ExchangeA', 'UK', 'ExchangeA', '*', '*', '*', 'Fee for using Exchange A', '*', 'GBP');

@data_to_write = select column1 as Code, column2 as TransactionPropertyKey, column3 as Country, column4 as Exchange, column5 as Custodian,
column6 as Counterparty, column7 as ExecutionBroker, column8 as Description, column9 as TransactionType, column10 as SettlementCurrency,
column10 as TransactionCurrency from @rules;
select * from Lusid.FeeRule.Writer where ToWrite = @data_to_write;

Example 3: Delete a fee rule

@data_to_write = select 'FeeRule-123' as Code, 'Delete' as WriteAction;
select * from Lusid.FeeRule.Writer where ToWrite = @data_to_write;