1

What I am trying to do is this :-

Given an pair (say DAI/ETH pair), i want to display the latest 10-15 trades (buy, sell, add to pool and remove from pool) and also display a graph of price for that pair.

How can i get the relevent data using uniswap js sdk/api?

1

You can use the Uniswap TheGraph for this! For example a query to get the last 10 swaps from the DAI/ETH pair would be:

{
    swaps(first: 10, where: { pair: "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11" } orderBy: timestamp, orderDirection: desc) {
      transaction {
        id
        timestamp
      }
      id
      pair {
        token0 {
          id
          symbol
        }
        token1 {
          id
          symbol
        }
      }
      amount0In
      amount0Out
      amount1In
      amount1Out
      amountUSD
      to
    }
}

You can play around with queries at: https://thegraph.com/explorer/subgraph/uniswap/uniswap-v2. Integration into the frontend would happen with something like Apollo Client.

In fact this is also what the Uniswap Info is doing. It's open-source, so look around for example queries and how to use them.

For more information on how TheGraph and queries work, I just posted a blog-post about it: https://soliditydeveloper.com/thegraph.

| improve this answer | |
  • Thanks a lot. I'll check them all. You are a life saver. – Hentai Ousama Sep 9 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.