From 2097a6f4bc95d69f3283e4602d3e7b49d36153eb Mon Sep 17 00:00:00 2001 From: Lou-Kamades Date: Tue, 12 Sep 2023 12:20:18 -0500 Subject: [PATCH] update calcs for lifetime trade volume --- utils/account.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/utils/account.ts b/utils/account.ts index 0f1aa79e..a2cb1a72 100644 --- a/utils/account.ts +++ b/utils/account.ts @@ -88,7 +88,12 @@ export const fetchVolumeTotals = async (mangoAccountPk: string) => { return combinedData.reduce((a, c) => { const entries: AccountVolumeTotalData[] = Object.entries(c) const marketVol = entries.reduce((a, c) => { - return a + c[1].volume_usd + let volumeUsd = c[1].volume_usd + if (!c[0].includes('PERP')) { + // The spot API reports volume by token so volume needs to be divided by 2 + volumeUsd = volumeUsd / 2 + } + return a + volumeUsd }, 0) return a + marketVol }, 0) @@ -118,7 +123,11 @@ const formatHourlyVolumeData = (data: HourlyAccountVolumeData[]) => { entry = { time: timestamp, total_volume_usd: 0, markets: {} } formattedData.push(entry) } - const objVolumeDecimal = new Decimal(obj[market][timestamp].volume_usd) + let objVolumeDecimal = new Decimal(obj[market][timestamp].volume_usd) + if (!market.includes('PERP')) { + // The spot API reports volume by token so volume needs to be divided by 2 + objVolumeDecimal = objVolumeDecimal.div(2) + } if (objVolumeDecimal.gt(0)) { // Increment the total_volume_usd by the volume_usd value entry.total_volume_usd = new Decimal(entry.total_volume_usd)