Accessing price data on "all" decentralized exchanges

1inch aggregates most DEXes. by using 1inch plugin you use most dexes

Is it possible to access the dex prices individually? e.g. if I specifically wanted the uniswap or bancor price?

1 Like

Hey @b7011343 :grinning:

If you look at the documentation that Ivan posted, you will find the function:

async function getQuote() {
  const quote = await Moralis.Plugins.oneInch.quote({
    chain: 'bsc', // The blockchain you want to use (eth/bsc/polygon)
    fromTokenAddress: '0x0da6ed8b13214ff28e9ca979dd37439e8a88f6c4', // The token you want to swap
    toTokenAddress: '0x6fd7c98458a943f469e1cf4ea85b173f5cd342f4', // The token you want to receive
    amount: 1000,
  });
  console.log(quote);
}

You can try to specify protocols option:

async function getQuote() {
  const quote = await Moralis.Plugins.oneInch.quote({
    chain: 'bsc', // The blockchain you want to use (eth/bsc/polygon)
    fromTokenAddress: '0x0da6ed8b13214ff28e9ca979dd37439e8a88f6c4', // The token you want to swap
    toTokenAddress: '0x6fd7c98458a943f469e1cf4ea85b173f5cd342f4', // The token you want to receive
    amount: 1000,
    protocols: ""
  });
  console.log(quote);
}

Protocols list you can find on 1 inch swagger by calling this API:

3 Likes

Let me know how it will work for you :raised_hands:

1 Like

not individually - you get the best price across all exchanges

EDIT: I see @Yomoo posted about protocols variable, it may be able to filer exchanges like you want

1 Like

Anyway I’m not sure it is the best solution. Beacuse it’s more for specifying swap routing and not for fetching prices @b7011343

Is there a better solution you could suggest?

You have really tricky case. If you want to create arbitrage bot I don’t think that using not on-chain data is a good idea. You will probably need to call prices from the smart contracts at least to check the information received from the api. And it should be really fast. Speed is important to successful arbitrage. So the most convenient solution is to use a custom smart contract and get only on-chain data

1 Like

Ok I will look into this. If I do it this way I imagine I will need to implement the logic for each dex individually.