Skip to content

Framework to develop and back-test online strategies for Uniswap v3 liquidity provision.

License

Notifications You must be signed in to change notification settings

yogi-bo/uniswap-v3-online-framework

Repository files navigation

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:

  1. uniswapv3data: Python lib to download Uniswap swap history from Google BigQuery.
  2. uniswapv3simulator: Go package to simulate strategies on historical Uniswap data efficiently.
  3. 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

BIGQUERY_CREDENTIALS_PATH = 'data/bigquery_auth.json'
OUTPUT_FILE_PATH = 'data/uniswap_data.csv.gz'
POOL_ADDRESS = '0x3416cF6C708Da44DB2624D63ea0AAef7113527C6'

BigQueryUniswapV3Downloader(BIGQUERY_CREDENTIALS_PATH).download_pool_data(POOL_ADDRESS, DATE_BEGIN, DATE_END).to_csv(OUTPUT_FILE_PATH)

Notice

This is a very simplified model that does not take into account all effects, such as gas fees. Use at your own risk.