fix(markets): use position decimals in notional calculation (#6125)
This commit is contained in:
parent
a77bb06b2f
commit
bb2464ddc2
@ -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'
|
||||
|
@ -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 (
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
@ -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'
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user