mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
types: add truncate quote quantity method
This commit is contained in:
parent
7060fd4ecb
commit
7d4d2f3e41
|
@ -71,6 +71,19 @@ func (m Market) TruncateQuantity(quantity fixedpoint.Value) fixedpoint.Value {
|
|||
return fixedpoint.MustNewFromString(qs)
|
||||
}
|
||||
|
||||
// TruncateQuoteQuantity uses the tick size to truncate floating number, in order to avoid the rounding issue
|
||||
func (m Market) TruncateQuoteQuantity(quantity fixedpoint.Value) fixedpoint.Value {
|
||||
var ts = m.TickSize.Float64()
|
||||
var prec = int(math.Round(math.Log10(ts) * -1.0))
|
||||
var pow10 = math.Pow10(prec)
|
||||
|
||||
qf := math.Trunc(quantity.Float64() * pow10)
|
||||
qf = qf / pow10
|
||||
|
||||
qs := strconv.FormatFloat(qf, 'f', prec, 64)
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user