You can use the address, xBTRFLY got itâs value too.
Youâre checking for a different address, thatâs why you got a different result
But the value for xBTRFLY is way off. It should be about the same as BTRFLY.
Their docs say xBTRFLY is deprecated, so that may be why. Canât seem to swap for it on exchanges. If it should be 1 to 1 in reality (as in docs, it was given in return for staked BTRFLY), then you can just use BTRFLY.
Thanks, but this is not super relevant, because we are getting a historical price. xBTRFLY was not deprecated as of the block we are requesting.
The issue is that the Moralis API is returning a wildly incorrect price. If thereâs no liquidity, it should return the âNot enough liquidityâ error, in which case we have code that falls back to proxy tokens (such as BTRFLY in this case). But when Moralis returns a price, we believe itâŚ
I think that sometimes getTokenPrice can return prices like that when the liquidity is low
That is not an acceptable answer.
If we say âsometimes itâs wrongâ that is the same as saying âdonât trust this API.â
How do we detect when itâs going to return crazy prices?
you could try to use /{pair_address}/reserves endpoint to get the exact liquidity reserves values, not sure if it will work in your case
Can you please check if it will work in this case, since this is a tech support question and you are providing support for a paid product?
If the liquidity is not sufficient to return an accurate price, I think youâve set the liquidity threshold too low in the API.
do you know what were to tokens in the liquidity pool at that time?
No - thatâs your job . We just use the price API Moralis provides.
As the price is obviously incorrect, the alternative is to just use BTRFLY address which according to the protocol should have been matching xBTRFLY at the time - this returns $3209 so in the same range as the chart which is what youâre using as a comparison anyway.
If it is user inputted, then you can set a case for it by default where it uses the BTRFLY contract address instead.
We have that case coded. It uses the fallback token (in this case BTRFLY) if the primary token the user inputs (in this case xBTRYFLY) does not return a price from the Moralis price API. However, in this case, it does return a price, and itâs a very wrong price. So this code does not kick in.
The other way to code it would be to try the fallback token first, but that is no good because sometimes the fallback token does not trade in line with the primary. For example, if the user wants a quote for stETH and we fall back to ETH, that doesnât work when stETH breaks its peg.
If the user asks for an apple, you always try to give them an apple before falling back to a pear.
What we need is a price API that functions as advertised in the docs: If there is not enough liquidity to return an accurate price, we should get an error instead of a crazy price.
Related question: Iâm trying the price API with another token (PolyCub), and getting a liquidity pool errorâŚ
https://deep-index.moralis.io/api/v2/erc20/0x7cc15fef543f205bf21018f038f591c6bada941c/price?chain=polygon
âŚeven though it has $190k of liquidity on Sushiswap on Polygon right now:
So, sometimes thereâs plenty of liquidity and you COULD get a good price but return an error. Other times, it seems like thereâs not enough liquidity and instead of returning an error, Moralis returns a crazy price. This is pretty difficult to code around.
Can I make a suggestion? Since the price API already checks the liquidity (to decide whether to return an error or return a price), what donât you just return the liquidity in the API response, along with the price? Then each of us developers can set their own threshold.
the problem with that I think is that we only track quickswap on polygon now
- I think you are responding to the POLYCUB issue. So whatâs the liquidity you are seeing in quickswap?
- Please address the xBTRFLY issue as well.
it could be no liquidity in quickswap if there is no trading pair there for that token, it is the same error when there is no trading pair
for xBTRFLY:
https://deep-index.moralis.io/api/v2/0xcc94faf235cc5d3bf4bed3a30db5984306c86abc/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/pairAddress?chain=eth&exchange=sushiswapv2
=>
{
"token0": {
"address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"name": "Wrapped Ether",
"symbol": "WETH",
"decimals": "18",
"logo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png",
"logo_hash": "0a7fc292596820fe066ce8ce3fd6e2ad9d479c2993f905e410ef74f2062a83ec",
"thumbnail": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2_thumb.png",
"block_number": null,
"validated": null,
"created_at": "2022-01-20T10:39:55.818Z"
},
"token1": {
"address": "0xcc94faf235cc5d3bf4bed3a30db5984306c86abc",
"name": "xBTRFLY",
"symbol": "xBTRFLY",
"decimals": "9",
"logo": null,
"logo_hash": null,
"thumbnail": null,
"block_number": "13825631",
"validated": 1,
"created_at": "2022-01-20T10:39:55.818Z"
},
"pairAddress": "0xed9193c3c0a9d5f77cd6d1ca18f14ce9e19ccad9"
}
https://deep-index.moralis.io/api/v2/0xed9193c3c0a9d5f77cd6d1ca18f14ce9e19ccad9/reserves?chain=eth&to_block=13973890
=>
{
"reserve0": "19729909330800231",
"reserve1": "535678"
}
- For POLYCUB: You said it could be no liquidity. Is it actually no liquidity on Quickswap?
- For xBTRYFLY is this enough liquidity? How much is required? Whatâs the threshold that throws the error?