tradingstrategy-ai / trade-executor

A Python framework for managing positions and trades in DeFi
https://tradingstrategy.ai
Other
101 stars 28 forks source link

Add strategy fees to metadata payload #1005

Closed kenkunz closed 2 weeks ago

kenkunz commented 1 month ago

Goal

As a frontend developer (or another consumer of Trade Executor APIs), I want a given strategy's fees to be available in the metadata endpoint payload, so that I can display the strategy's fees without having to store frontend-specific configuration.

Background

See tradingstrategy-ai/frontend#774

Also see fees page of any strategy:

image

Strategies can have different fees, so the fee info should be configured and made available at the strategy level. As a short-term solution, frontend has added a fees section to the frontend-specific strategy configuration. This is not where this data belongs – all other important strategy-specific configuration is defined at the strategy level and made available via the metadata endpoint.

While discussing this need, @miohtama indicated that some of the fee information is configured on the Enzyme vault and should be available from Enzyme smart contracts. Not all strategies use an Enzyme vault for asset management. Regardless of the way assets are managed for a given strategy, frontend (and other API consumers) should have a single, consistent way to retrieve fee info. The logical place for normalized fee info to be normalised and consolidated is the metadata endpoint.

Proposed structure

A new top-level fees property should be added to metadata payload with the following properties (corresponding to the data shown on the fees page):

{
  "fees": {
    "management_fee": 0,
    "trading_strategy_protocol_fee": 0.02,
    "strategy_developer_fee": 0.1
  }
}

Each of the fees is optional. If a fee is included, the value should be a non-negative decimal (float) representation of a percent – e.g. 0.02 for a value that will be displayed as 2.0%. If a fee is not included, it will default to 0 on frontend.

Acceptance criteria

For all strategies that have been deployed with this update:

  1. The metadata payload includes a top level fees property, with a value of an object with the above properties.
  2. The fees object includes one or more of the following properties: management_fee, trading_strategy_protocol_fee, strategy_developer_fee.
  3. The value of every fees property is a non-negative decimal representation of the fee percent (e.g., for a fee of 2.0%, the value would be 0.02).
kenkunz commented 1 month ago

After some discussion on discord, we agreed to:

The acceptance criteria have been updated.

kenkunz commented 2 weeks ago

@hieuh25 I reviewed the current metadata of all live strategies. There are currently two strategies that should have fees defined. One of them has fees as string values (see comment above). The other has null values. The table provides further detail on what needs to be updated.

Strategy Current `fees` value Correct `fees` value
enzyme-ethereum-btc-eth-stoch-rsi
{
  "management_fee": null,
  "trading_strategy_protocol_fee": null,
  "strategy_developer_fee": null
}
{
  "management_fee": 0,
  "trading_strategy_protocol_fee": 0.02,
  "strategy_developer_fee": 0.1
}
enzyme-polygon-eth-rolling-ratio
{
  "management_fee": "0%",
  "trading_strategy_protocol_fee": "2%",
  "strategy_developer_fee": "5%"
}
{
  "management_fee": 0,
  "trading_strategy_protocol_fee": 0.02,
  "strategy_developer_fee": 0.05
}

Let me know if you have any questions.

kenkunz commented 2 weeks ago

Reviewed updates made by @hieuh25 – looks good 👍