---
title: "Lusid.FeeRule.Writer"
slug: "lusidfeerulewriter"
updated: 2024-08-22T09:23:32Z
published: 2024-08-22T09:23:32Z
canonical: "support.lusid.com/lusidfeerulewriter"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://support.lusid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Lusid.FeeRule.Writer

| **Type** | **Read/write** | **Author** | **Availability** |
| --- | --- | --- | --- |
| [Data provider](/v1/docs/what-are-a-data-provider-and-a-direct-provider) | Write | FINBOURNE | Provided with LUSID |

Providing you have sufficient [access control permissions](/v1/docs/creating-policies-to-control-access-to-providers-for-different-luminesce-end-users), the `Lusid.FeeRule.Writer` provider enables you to write a [Luminesce SQL query](/v1/docs/understanding-the-luminesce-sql-query-syntax) that either upserts or deletes [fee and commission rules](/v1/docs/managing-order-fees-and-commissions) 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](/v1/docs/how-do-i-create-a-property-type).

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](/v1/docs/lusidfeerule)

## Basic usage

```sql
@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](/v1/docs/what-tools-are-available-to-write-luminesce-queries):

```sql
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:

| **Operation** | **Specify using...** | **Mandatory fields** |
| --- | --- | --- |
| Upsert | `'Upsert' as WriteAction` (or omit) | `CodeTransactionPropertyKeyCountryExchangeCustodianCounterpartyExecutionBrokerDescriptionTransactionTypeSettlementCurrencyTransactionCurrency` |
| Delete | `'Delete' as WriteAction` | `Code` |

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](/v1/docs/what-tools-are-available-to-write-luminesce-queries):

```sql
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 `WriteError`, `WriteErrorCode` 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](https://github.com/finbourne/luminesce-examples/tree/master/examples).

### 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:

```sql
@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.

```sql
@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

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