Skip to main content

SDK for creating new strategies on Uniswap V3

git clone https://github.com/mellow-finance/mellow-strategy-sdk.git
cd mellow-strategy-sdk
python3 -m venv .venv
source .venv/bin/activate
pip install poetry
poetry install

or

python3 -m venv .venv
source .venv/bin/activate
pip install mellow_strategy_sdk

Getting Started

Import

from mellow_sdk.primitives import Pool, Token, Fee
from mellow_sdk.data import RawDataUniV3
from mellow_sdk.strategies import UniV3Passive
from mellow_sdk.backtest import Backtest
from mellow_sdk.viewers import RebalanceViewer, UniswapViewer, PortfolioViewer
from mellow_sdk.positions import BiCurrencyPosition, UniV3Position

Choose a pool

A typical notebook would start with downloading and preparing data for a specific pool. Let’s choose WBTC/WETH, fee 0.3% pool.

pool = Pool(Token.WBTC, Token.WETH, Fee.MIDDLE)

Get data

Аt the first run you need to download the data

data = RawDataUniV3(pool, 'data', reload_data=False).load_from_folder()

Use implemented strategy

univ3_passive = UniV3Passive(
    lower_price=data.swaps['price'].min() - 1,
    upper_price=data.swaps['price'].max() + 1,
    pool=pool,
    gas_cost=0.,
    name='passive'
)

Backtest

Next step is to run backtest using your strategy and data

bt = Backtest(univ3_passive)
portfolio_history, rebalance_history, uni_history = bt.backtest(data.swaps)

Visualize

Next visualize results

rv = RebalanceViewer(rebalance_history)
uv = UniswapViewer(uni_history)
pv = PortfolioViewer(portfolio_history, pool)

# Draw portfolio stats, like value, fees earned, apy
fig1, fig2, fig3, fig4, fig5, fig6 = pv.draw_portfolio()

# Draw Uniswap intervals
intervals_plot = uv.draw_intervals(data.swaps)

# Draw rebalances
rebalances_plot = rv.draw_rebalances(data.swaps)

# Calculate df with portfolio stats
stats = portfolio_history.calculate_stats()
intervals_plot.show()
https://raw.githubusercontent.com/mellow-finance/mellow-strategy-sdk/main/examples/getting_started_intervals.png
rebalances_plot.show()
https://raw.githubusercontent.com/mellow-finance/mellow-strategy-sdk/main/examples/getting_started_rebalances.png
fig2.show()
https://raw.githubusercontent.com/mellow-finance/mellow-strategy-sdk/main/examples/getting_started_fig2.png
fig4.show()
https://raw.githubusercontent.com/mellow-finance/mellow-strategy-sdk/main/examples/getting_started_fig4.png
fig6.show()
https://raw.githubusercontent.com/mellow-finance/mellow-strategy-sdk/main/examples/getting_started_fig6.png

Congratulations! Now you have the results of your strategy backtest on the real UniV3 data!

Metadata

Release files for mellow-strategy-sdk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for mellow-strategy-sdk 0.1.1
File Interpreter ABI Platform Actions
mellow_strategy_sdk-0.1.1-py3-none-any.whl Python 3 none any Details for mellow_strategy_sdk-0.1.1-py3-none-any.whl

Release files / mellow_strategy_sdk-0.1.1-py3-none-any.whl

Download URL mellow_strategy_sdk-0.1.1-py3-none-any.whl
Size 26.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cefc9c7f8cd4c4af46ec4df8d0f62fe67fee6deebd6e296318ad626cce2d4f9c
BLAKE2b-256 checksum
How to use checksums
c52593a041852e141db8be5b95865e680ac7886144bd94f9381a2c2750a861da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.9.12 Darwin/21.4.0

Security for mellow-strategy-sdk 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page