fix(markets): use position decimals in notional calculation (#6125)

This commit is contained in:
Matthew Russell 2024-03-28 11:07:06 +00:00 committed by GitHub
parent a77bb06b2f
commit bb2464ddc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 7 deletions

View File

@ -170,7 +170,12 @@ export const useMarketsColumnDefs = () => {
const vol = candles ? calcCandleVolume(candles) : '0';
const quoteName = getQuoteName(data);
const volPrice =
candles && calcCandleVolumePrice(candles, data.decimalPlaces);
candles &&
calcCandleVolumePrice(
candles,
data.decimalPlaces,
data.positionDecimalPlaces
);
const volume =
data && vol && vol !== '0'

View File

@ -10,10 +10,10 @@ import { useT } from '../../use-t';
interface Props {
marketId?: string;
positionDecimalPlaces?: number;
formatDecimals?: number;
initialValue?: string;
marketDecimals: number;
positionDecimalPlaces: number;
quoteUnit?: string;
}
@ -41,7 +41,11 @@ export const Last24hVolume = ({
: initialValue;
const candleVolumePrice = oneDayCandles
? calcCandleVolumePrice(oneDayCandles, marketDecimals)
? calcCandleVolumePrice(
oneDayCandles,
marketDecimals,
positionDecimalPlaces
)
: initialValue;
return (

View File

@ -177,7 +177,11 @@ describe('calcCandleVolumePrice', () => {
periodStart: '2022-05-18T14:08:27.693537312Z',
},
];
const decimalPlaces = 2;
expect(calcCandleVolumePrice(candles, decimalPlaces)).toEqual('2');
const marketDecimals = 3;
const positionDecimalPlaces = 2;
expect(
calcCandleVolumePrice(candles, marketDecimals, positionDecimalPlaces)
).toEqual('0.002');
});
});

View File

@ -178,12 +178,16 @@ export const calcCandleVolume = (candles: Candle[]): string | undefined =>
*/
export const calcCandleVolumePrice = (
candles: Candle[],
decimalPlaces: number
marketDecimals: number,
positionDecimals: number
): string | undefined =>
candles &&
candles.reduce(
(acc, c) =>
new BigNumber(acc).plus(toBigNum(c.notional, decimalPlaces)).toString(),
new BigNumber(acc)
// Using notional both price and size need conversion with decimals, we can acheive the same result by just combining them
.plus(toBigNum(c.notional, marketDecimals + positionDecimals))
.toString(),
'0'
);