I am trying to use the Uniswap SDK to get historical rates between two coins on a pool. I believe the rate is simply just xy = k
, where k
is a constant. If someone buys n
coins of x
, the cost in terms of y
coins would be whatever m
value that makes the equation (x - n)(y + m) = k
still hold.
I’ve been looking all over the Uniswap’s SDK page and can’t really find where I can find the historical data regarding this xy = k
curve. I think it should be possible, but I’m not exactly sure where to find it.
I’m also looking for how the current swap rate (that is what the current values of x
and y
are).
I think it can be done via GraphQL, but I’m looking for a solution using the SDK. Can anyone help?
2
Answers
with uniswap SDK you can only get the current swap rate. You’d need to combine this with GraphQL API to get historical data.
Hope this helps!
Two options
You can download historical rates from Trading Strategy websites as a Parquet file (preprocessed).
You can ask from an archive node using JSON-RPC, and set a
block_number
to a past block for youreth_call
RPC method, which calls the Uniswap smart contract to get token0/token1 ratio.You will find some historical Uniswap v3 price tutorial here.