Framework to develop and back-test online strategies for Uniswap v3 liquidity provision.
Uniswap v3 Online Strategy Framework and Simulator
Introduction
This repository contains a framework to develop and back-test online strategies for Uniswap v3 liquidity provision, including:
- uniswapv3data: Python lib to download Uniswap swap history from Google BigQuery.
- uniswapv3simulator: Go package to simulate strategies on historical Uniswap data efficiently.
- Exponential Weighted Market Maker.ipynb: Jupyter Notebook example using the framework to simulate the Exponential Weights strategy described in Uniswap Liquidity Provision: An Online Learning Approach.
Implement your own strategy
Adding another strategy to uniswapv3simulator is easy. Implement the following interface in onlinestrategy:
type Strategy interface { NextRange(onlineStrategy *OnlineStrategy) (Range, error) } NextRange should return in which price range to provide liquidity on the next step.
Use your implementation instead of StaticStrategy in the main function.
Download Uniswap Historical Data
You can use uniswapv3simulator to download historical swap data from the Ethereum dataset on Google BitQuery.
First, you should generate a service account key and download the authentication details to a local json file. Then you can use the lib as follows:
from uniswapv3data.bigquery_downloader import BigQueryUniswapV3Downloader
BIGQUERYCREDENTIALSPATH = 'data/bigquery_auth.json' OUTPUTFILEPATH = 'data/uniswap_data.csv.gz' POOL_ADDRESS = '0x3416cF6C708Da44DB2624D63ea0AAef7113527C6'
BigQueryUniswapV3Downloader(BIGQUERYCREDENTIALSPATH).downloadpooldata(POOLADDRESS, DATEBEGIN, DATEEND).tocsv(OUTPUTFILEPATH)
Notice
This is a very simplified model that does not take into account all effects, such as gas fees. Use at your own risk.