tradingstrategy-ai / web3-ethereum-defi

A Python library for trading automation on DeFi, data research and integration. Supporting Uniswap, Aave, Chainlink, USDC and other protocols.
https://tradingstrategy.ai
MIT License
613 stars 131 forks source link

Investigate Uniswap v3 and getting historical price data in good format #4

Closed miohtama closed 2 years ago

miohtama commented 2 years ago

Question that needs to be answered:

Can be a single pool price at milestone 1, later expanded to cover auto routing and multi-hop trades.

miohtama commented 2 years ago

Related Uniswap v3 in-house project

https://github.com/Uniswap/smart-order-router/blob/main/src/routers/alpha-router/functions/get-candidate-pools.ts

hieuh25 commented 2 years ago

Search on Github and PyPI about Python and Uniswap v3 reveals that there isn't any one library that could do this at the moment. In short the code to get data out of Uniswap v3 is very fragmented for the time being. Some notable ones are:

GraphQL based solution can use existing subgraphs like:

There are several onchain oracle solutions too, might not be very useful for above purpose:

miohtama commented 2 years ago

We need to decide if we take JSON-RPC event-based approach or GraphQL based approach.

Let's tackle the Uni v3 deployment first.

miohtama commented 2 years ago

Some notebooks dealing with Uniswap v3 backtesting

https://github.com/nguyenhieuec/uniswap_backtester/blob/master/notebooks/monte_carlo_simulation.ipynb

miohtama commented 2 years ago

Also saw this

https://ethereum.stackexchange.com/a/123333/620

hieuh25 commented 2 years ago

Also saw this

https://ethereum.stackexchange.com/a/123333/620

I added a test for that method this morning: https://github.com/tradingstrategy-ai/eth-hentai/pull/6/files#diff-59cf62830f8e4e3131187561bfa500d2fdf0a14a48a9c33d91fbc1867a44ad80R111-R115 There are some good insights in the answer though