How to get the historical data of high and low price of a token?
You can get the historical token price from gettokenprice
function by using to_block
parameter.
https://docs.moralis.io/moralis-dapp/web3-api/token#gettokenprice
How can I find the high price and low price of a particular day?
There is no direct way to check this. You will have to create multiple API requests with a series of block numbers and calculate the high and low prices in your app.
I have read the whole documentation to find the highs and lows. But could not able to find that by calling which apis I would be able to find the highs and lows. Can u please tell me If you know that which apis I need to call in order to achieve my goal?
You need to calculate the high and low on your app. There is no api for it
Here is an example code:
// gets the latest block on eth chain
const options = {
chain: "eth",
date: new Date().toISOString(),
};
const date = await Moralis.Web3API.native.getDateToBlock(options);
let block = date.block;
// runs a loop over 10 different block numbers to get different prices of the token
let priceArray = [];
for (let i = 0; i < 10; i++) {
const options = {
address: "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
chain: "eth",
exchange: "uniswap-v3",
to_block: block
}
const price = await Moralis.Web3API.token.getTokenPrice(options);
priceArray.push(price.usdPrice.toFixed(4));
block -= 100;
}
// calculate the min and max of the token price after getting the prices
console.log("Max Price ",Math.max(...priceArray));
console.log("Min Price ",Math.min(...priceArray));
Your solution will give me the price of 10 different blocks and I will be able to get the result of min and max from those blocks. But what if there exists any other block on a particular date whose price is max than what we obtain from your logic. Same applies for min value. Means I donβt think it will give me the accurate value of max and min for a particular day.
that code was an example. You need to update it to get the prices at different blocks as per your use-case.