Skip to content

Commit

Permalink
Merge pull request #9 from galacticcouncil/volume-fix
Browse files Browse the repository at this point in the history
fix volume & categorize endpoints
  • Loading branch information
green-jay authored Nov 14, 2023
2 parents 635e0dd + add14f5 commit e545664
Show file tree
Hide file tree
Showing 18 changed files with 331 additions and 315 deletions.
58 changes: 0 additions & 58 deletions app/routes/defillama/v1/tvl.mjs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,29 @@ import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs";
import { getAssets } from "../../../../../../helpers/asset_helpers.mjs";

const sqlQueries = yesql(
path.join(dirname(), "queries/hydradx-ui/v1/stats/current"),
path.join(dirname(), "queries/hydradx-ui/v1/stats/charts"),
{
type: "pg",
}
);

export default async (fastify, opts) => {
fastify.route({
url: "/price/:asset?",
url: "/lrna",
method: ["GET"],
schema: {
description: "Current asset price in USDT.",
description: "Chart data for LRNA price & supply.",
tags: ["hydradx-ui/v1"],
params: {
type: "object",
properties: {
asset: {
type: "string",
description: "Asset (id)",
},
},
},
response: {
200: {
description: "Success Response",
type: "array",
items: {
type: "object",
properties: {
price_usd: { type: "number" },
timestamp: { type: "string" },
lrna_supply: { type: "number" },
lrna_price: { type: "number" },
},
},
},
Expand All @@ -44,10 +37,9 @@ export default async (fastify, opts) => {
handler: async (request, reply) => {
const asset = request.params.asset ? request.params.asset : null;

const sqlQuery = sqlQueries.statsCurrentPrice({ asset });
const sqlQuery = sqlQueries.statsChartLrna();

let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsCurrentPrice"] };
cacheSetting.key = cacheSetting.key + "_" + asset;
let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsChartLrna"] };

const result = await cachedFetch(
fastify.pg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import path from "path";
import { dirname } from "../../../../../../variables.mjs";
import { CACHE_SETTINGS } from "../../../../../../variables.mjs";
import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs";
import { getAssets } from "../../../../../../helpers/asset_helpers.mjs";

const sqlQueries = yesql(
path.join(dirname(), "queries/hydradx-ui/v1/stats/current"),
path.join(dirname(), "queries/hydradx-ui/v1/stats/charts"),
{
type: "pg",
}
Expand All @@ -16,13 +17,13 @@ export default async (fastify, opts) => {
url: "/tvl/:asset?",
method: ["GET"],
schema: {
description: "Current Omnipool TVL.",
description: "Chart data for Omnipool TVL.",
tags: ["hydradx-ui/v1"],
params: {
type: "object",
properties: {
asset: {
type: "string",
type: "integer",
description: "Asset (id). Leave empty for all assets.",
},
},
Expand All @@ -34,6 +35,7 @@ export default async (fastify, opts) => {
items: {
type: "object",
properties: {
timestamp: { type: "string" },
tvl_usd: { type: "number" },
},
},
Expand All @@ -43,9 +45,9 @@ export default async (fastify, opts) => {
handler: async (request, reply) => {
const asset = request.params.asset ? request.params.asset : null;

const sqlQuery = sqlQueries.statsCurrentTvl({ asset });
const sqlQuery = sqlQueries.statsChartTvl({ asset });

let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsCurrentTvl"] };
let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1statsChartTvl"] };
cacheSetting.key = cacheSetting.key + "_" + asset;

const result = await cachedFetch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,48 @@ import { CACHE_SETTINGS } from "../../../../../../variables.mjs";
import { cachedFetch } from "../../../../../../helpers/cache_helpers.mjs";

const sqlQueries = yesql(
path.join(dirname(), "queries/hydradx-ui/v1/stats/current"),
path.join(dirname(), "queries/hydradx-ui/v1/stats/charts"),
{
type: "pg",
}
);

export const VALID_TIMEFRAMES = ["hourly", "daily"];

export default async (fastify, opts) => {
fastify.route({
url: "/volume/:asset?",
method: ["GET"],
schema: {
description: "Current 24h rolling trading volume.",
description: "Chart data for Omnipool trading volume.",
tags: ["hydradx-ui/v1"],
params: {
type: "object",
properties: {
asset: {
type: "string",
type: "integer",
description: "Asset (id). Leave empty for all assets.",
},
},
},
querystring: {
type: "object",
properties: {
timeframe: {
type: "string",
enum: VALID_TIMEFRAMES,
default: "daily",
},
},
},
response: {
200: {
description: "Success Response",
type: "array",
items: {
type: "object",
properties: {
timestamp: { type: "string" },
volume_usd: { type: "number" },
},
},
Expand All @@ -42,11 +55,14 @@ export default async (fastify, opts) => {
},
handler: async (request, reply) => {
const asset = request.params.asset ? request.params.asset : null;
const timeframe = request.query.timeframe;

const sqlQuery = sqlQueries.statsCurrentVolume({ asset });
const sqlQuery = sqlQueries.statsChartVolume({ asset, timeframe });

let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsCurrentVolume"] };
cacheSetting.key = cacheSetting.key + "_" + asset;
let cacheSetting = {
...CACHE_SETTINGS["hydradxUiV1statsChartVolume"],
};
cacheSetting.key = cacheSetting.key + "_" + asset + "_" + timeframe;

const result = await cachedFetch(
fastify.pg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@ const sqlQueries = yesql(path.join(dirname(), "queries/hydradx-ui/v1/stats"), {

export default async (fastify, opts) => {
fastify.route({
url: "/lrna",
url: "/price/:asset?",
method: ["GET"],
schema: {
description: "LRNA price & supply for the HydraDX stats page.",
description: "Current asset price in USDT.",
tags: ["hydradx-ui/v1"],
params: {
type: "object",
properties: {
asset: {
type: "integer",
description: "Asset (id)",
},
},
},
response: {
200: {
description: "Success Response",
type: "array",
items: {
type: "object",
properties: {
timestamp: { type: "string" },
lrna_supply: { type: "number" },
lrna_price: { type: "number" },
price_usd: { type: "number" },
},
},
},
Expand All @@ -34,9 +41,10 @@ export default async (fastify, opts) => {
handler: async (request, reply) => {
const asset = request.params.asset ? request.params.asset : null;

const sqlQuery = sqlQueries.statsLrna();
const sqlQuery = sqlQueries.statsPrice({ asset });

let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsLrna"] };
let cacheSetting = { ...CACHE_SETTINGS["hydradxUiV1StatsPrice"] };
cacheSetting.key = cacheSetting.key + "_" + asset;

const result = await cachedFetch(
fastify.pg,
Expand Down
6 changes: 2 additions & 4 deletions app/routes/hydradx-ui/v1/stats/tvl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from "path";
import { dirname } from "../../../../../variables.mjs";
import { CACHE_SETTINGS } from "../../../../../variables.mjs";
import { cachedFetch } from "../../../../../helpers/cache_helpers.mjs";
import { getAssets } from "../../../../../helpers/asset_helpers.mjs";

const sqlQueries = yesql(path.join(dirname(), "queries/hydradx-ui/v1/stats"), {
type: "pg",
Expand All @@ -14,13 +13,13 @@ export default async (fastify, opts) => {
url: "/tvl/:asset?",
method: ["GET"],
schema: {
description: "Omnipool TVL for the HydraDX stats page.",
description: "Current Omnipool TVL.",
tags: ["hydradx-ui/v1"],
params: {
type: "object",
properties: {
asset: {
type: "string",
type: "integer",
description: "Asset (id). Leave empty for all assets.",
},
},
Expand All @@ -32,7 +31,6 @@ export default async (fastify, opts) => {
items: {
type: "object",
properties: {
timestamp: { type: "string" },
tvl_usd: { type: "number" },
},
},
Expand Down
Loading

0 comments on commit e545664

Please sign in to comment.