Uniswap V3 Data Notebook#

In this notebook:

  • We use the TradingStrategy API to get data for 3 pairs on Uniswap V3

  • This is done for 3 pairs: eth_usdc, eth_usdt, and usdt_usdc

The following code block shows an example of some the data from the api

[1]:
import requests
import pandas as pd

pairs = {
    'eth_usdc': 'https://tradingstrategy.ai/api/candles?pair_id=2697765&exchange_type=uniswap_v3&time_bucket=4h',
    'usdt_usdc': 'https://tradingstrategy.ai/api/candles?pair_id=2711887&exchange_type=uniswap_v3&time_bucket=4h',
    'eth_usdt': 'https://tradingstrategy.ai/api/candles?pair_id=2697770&exchange_type=uniswap_v3&time_bucket=4h'

}

def get_candles(url: str) -> pd.DataFrame:
    x = requests.get(url)
    json = x.json()

    candles = pd.DataFrame.from_dict(json)
    candles.rename(columns = {'ts':'date','o':'open', 'h':'high','l':'low','c':'close','v':'volume'}, inplace = True)
    candles['timestamp'] = pd.to_datetime(candles['date'])
    candles = candles.set_index('date')
    return candles

pair_data = dict([ (k,get_candles(r)) for k,r in pairs.items()])

pair_data['usdt_usdc'].head()
[1]:
open high low close volume xr b s tc bv sv timestamp
date
2023-04-25T20:00:00 1.0002 1.0002 1.0001 1.0001 3.693619e+07 1.0 None None None None None 2023-04-25 20:00:00
2023-04-26T00:00:00 1.0001 1.0001 1.0001 1.0001 1.241267e+06 1.0 None None None None None 2023-04-26 00:00:00
2023-04-26T04:00:00 1.0001 1.0002 1.0001 1.0002 1.618425e+07 1.0 None None None None None 2023-04-26 04:00:00
2023-04-26T08:00:00 1.0002 1.0002 1.0001 1.0002 3.281721e+07 1.0 None None None None None 2023-04-26 08:00:00
2023-04-26T12:00:00 1.0002 1.0002 1.0002 1.0002 1.431288e+07 1.0 None None None None None 2023-04-26 12:00:00

Visual#

Here we visualize the prices and volumes of each of the 3 pairs.

[2]:
from tradingstrategy.charting.candle_chart import visualise_ohlcv

def get_figure(candles: pd.DataFrame, chart_name: str):
    return visualise_ohlcv(
            candles,
            height=600,
            theme="plotly_white",
            chart_name=chart_name,
            y_axis_name="Price",
            volume_axis_name="volume",
        )
figures = dict([ (k,get_figure(r, k)) for k,r in pair_data.items()])

figures['eth_usdc'].show()
figures['eth_usdt'].show()
figures['usdt_usdc'].show()