This PR adds the ability to quantize a Decimal to a multiple of a quantum (rounding towards zero as its the default rounding behaviour in rust). The name is chosen to maximize the information gained from reading it (as compared with just naming it quantize and expecting a different rounding behaviour).
The use cases are plenty with one example being the ability to pass exchange PriceFilter and QuantityFilter, e.g when you have a price estimate from some signal processing function like a moving average (312.95137, stored in Decimal<i64, 5>) and the exchange expects you to be quantized to the tick size of 0.5 units of the quote currency, then this method comes in handy and calling .quantize_toward_zero(Decimal::try_from_scaled(5, 1).unwrap()) will return a Decimal of value 312.5.
In principle other such methods could exist for different rounding modes, e.g quantize_round, quantize_ceil, quantize_floor but those are out of scope of this PR.
This PR adds the ability to quantize a
Decimal
to a multiple of aquantum
(rounding towards zero as its the default rounding behaviour in rust). The name is chosen to maximize the information gained from reading it (as compared with just naming itquantize
and expecting a different rounding behaviour).The use cases are plenty with one example being the ability to pass exchange
PriceFilter
andQuantityFilter
, e.g when you have a price estimate from some signal processing function like a moving average (312.95137
, stored inDecimal<i64, 5>
) and the exchange expects you to be quantized to the tick size of0.5
units of the quote currency, then this method comes in handy and calling.quantize_toward_zero(Decimal::try_from_scaled(5, 1).unwrap())
will return aDecimal
of value312.5
.In principle other such methods could exist for different rounding modes, e.g
quantize_round
,quantize_ceil
,quantize_floor
but those are out of scope of this PR.