types: add RoundDownQuantityByPrecision

This commit is contained in:
c9s 2023-05-15 16:29:25 +08:00
parent df842a04ee
commit aff5447e71
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -70,6 +70,12 @@ func (m Market) TruncateQuantity(quantity fixedpoint.Value) fixedpoint.Value {
return fixedpoint.MustNewFromString(qs) 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 { func (m Market) TruncatePrice(price fixedpoint.Value) fixedpoint.Value {
return fixedpoint.MustNewFromString(m.FormatPrice(price)) return fixedpoint.MustNewFromString(m.FormatPrice(price))
} }