From aff5447e7163ec363d0651646a77cfdea0ea6cad Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 15 May 2023 16:29:25 +0800 Subject: [PATCH] types: add RoundDownQuantityByPrecision --- pkg/types/market.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/types/market.go b/pkg/types/market.go index 99b2f9efb..6b7199798 100644 --- a/pkg/types/market.go +++ b/pkg/types/market.go @@ -70,6 +70,12 @@ func (m Market) TruncateQuantity(quantity fixedpoint.Value) fixedpoint.Value { return fixedpoint.MustNewFromString(qs) } +// RoundDownQuantityByPrecision uses the volume precision to round down the quantity +// This is different from the TruncateQuantity, which uses StepSize (it uses fewer fractions to truncate) +func (m Market) RoundDownQuantityByPrecision(quantity fixedpoint.Value) fixedpoint.Value { + return quantity.Round(m.VolumePrecision, fixedpoint.Down) +} + func (m Market) TruncatePrice(price fixedpoint.Value) fixedpoint.Value { return fixedpoint.MustNewFromString(m.FormatPrice(price)) }