Skip to content

Commit

Permalink
fix: handle reverse price for pair oraix/usdc (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
trungbach authored Feb 16, 2024
1 parent f7c05e8 commit 3bf6a34
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/oraidex-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
} from "./helper";
import { CACHE_KEY, cache, registerListener, updateInterval } from "./map-cache";
import { BigDecimal } from "@oraichain/oraidex-common/build/bigdecimal";
import { ORAIX_CONTRACT, USDC_CONTRACT } from "@oraichain/oraidex-common";

// cache

Expand Down Expand Up @@ -261,6 +262,29 @@ app.get("/v1/candles/", async (req: Request<{}, {}, {}, GetCandlesQuery>, res) =
return res.status(400).send("Not enough query params");

const candles = await duckDb.getOhlcvCandles(req.query);

// reverse data for pool oraix/usdc to display price asset in stable coin
const pairDenoms = req.query.pair.split("-");
if (pairDenoms[0] === USDC_CONTRACT && pairDenoms[1] === ORAIX_CONTRACT) {
const pairInfo = pairsWithDenom.find(
(pair) => pair.asset_denoms[0] === pairDenoms[0] && pair.asset_denoms[1] === pairDenoms[1]
);
if (!pairInfo) return res.status(400).send("Not found pair");

const currentBaseAssetPrice = await getPriceByAsset(pairInfo.asset_infos, "base_in_quote");
return res.status(200).send(
candles.map((candle) => {
return {
...candle,
open: 1 / candle.open,
close: 1 / candle.close,
low: 1 / candle.low,
high: 1 / candle.high,
volume: Math.floor(Number(candle.volume) / currentBaseAssetPrice)
};
})
);
}
res.status(200).send(candles);
} catch (error) {
res.status(500).send(error.message);
Expand Down

0 comments on commit 3bf6a34

Please sign in to comment.