update calcs for lifetime trade volume

This commit is contained in:
Lou-Kamades 2023-09-12 12:20:18 -05:00
parent e6db2d2267
commit 2097a6f4bc
No known key found for this signature in database
GPG Key ID: 87A166E4D7C01F30
1 changed files with 11 additions and 2 deletions

View File

@ -88,7 +88,12 @@ export const fetchVolumeTotals = async (mangoAccountPk: string) => {
return combinedData.reduce((a, c) => { return combinedData.reduce((a, c) => {
const entries: AccountVolumeTotalData[] = Object.entries(c) const entries: AccountVolumeTotalData[] = Object.entries(c)
const marketVol = entries.reduce((a, 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) }, 0)
return a + marketVol return a + marketVol
}, 0) }, 0)
@ -118,7 +123,11 @@ const formatHourlyVolumeData = (data: HourlyAccountVolumeData[]) => {
entry = { time: timestamp, total_volume_usd: 0, markets: {} } entry = { time: timestamp, total_volume_usd: 0, markets: {} }
formattedData.push(entry) 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)) { if (objVolumeDecimal.gt(0)) {
// Increment the total_volume_usd by the volume_usd value // Increment the total_volume_usd by the volume_usd value
entry.total_volume_usd = new Decimal(entry.total_volume_usd) entry.total_volume_usd = new Decimal(entry.total_volume_usd)