Price API Problem in case of low liquidity

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 :slight_smile: . 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…

…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.

You can add this suggestion on

Thanks. Done.
Would still appreciate an answer to the above.

the problem with that I think is that we only track quickswap on polygon now

  1. I think you are responding to the POLYCUB issue. So what’s the liquidity you are seeing in quickswap?
  2. 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:


  "token0": {
    "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
    "name": "Wrapped Ether",
    "symbol": "WETH",
    "decimals": "18",
    "logo": "",
    "logo_hash": "0a7fc292596820fe066ce8ce3fd6e2ad9d479c2993f905e410ef74f2062a83ec",
    "thumbnail": "",
    "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"


  "reserve0": "19729909330800231",
  "reserve1": "535678"
  1. For POLYCUB: You said it could be no liquidity. Is it actually no liquidity on Quickswap?
  2. For xBTRYFLY is this enough liquidity? How much is required? What’s the threshold that throws the error?

Gentle reminder on the two items above. Thanks.

1 Like

I’m not able to find this address 0x7cc15fef543f205bf21018f038f591c6bada941c on quickswap interface:

for xBTRYFLY, it looks like it has close to 0.2 WETH

The logic is the following one:

  • we calculate the price based on the average of all stablecoin pairs (with at least 250USD liquidity)
  • we look for WETH (or any other whitelisted tokens) to calculate the price. This has no liquidity threshold