mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
xmaker: truncate quantity when hedging
This commit is contained in:
parent
05a0745d08
commit
902e27ede4
|
@ -501,6 +501,7 @@ func (s *Strategy) Hedge(ctx context.Context, pos fixedpoint.Value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
quantity := fixedpoint.Abs(pos)
|
quantity := fixedpoint.Abs(pos)
|
||||||
|
quantity = s.sourceMarket.TruncateQuantity(quantity)
|
||||||
|
|
||||||
if pos < 0 {
|
if pos < 0 {
|
||||||
side = types.SideTypeSell
|
side = types.SideTypeSell
|
||||||
|
|
|
@ -8,6 +8,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/leekchan/accounting"
|
"github.com/leekchan/accounting"
|
||||||
|
|
||||||
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Duration time.Duration
|
type Duration time.Duration
|
||||||
|
@ -93,6 +95,12 @@ type Market struct {
|
||||||
TickSize float64 `json:"tickSize,omitempty"`
|
TickSize float64 `json:"tickSize,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TruncateQuantity uses the step size to truncate floating number, in order to avoid the rounding issue
|
||||||
|
func (m Market) TruncateQuantity(quantity fixedpoint.Value) fixedpoint.Value {
|
||||||
|
stepRound := math.Pow10(-int(math.Log10(m.StepSize)))
|
||||||
|
return fixedpoint.NewFromFloat(math.Trunc(quantity.Float64()*stepRound) / stepRound)
|
||||||
|
}
|
||||||
|
|
||||||
func (m Market) BaseCurrencyFormatter() *accounting.Accounting {
|
func (m Market) BaseCurrencyFormatter() *accounting.Accounting {
|
||||||
a := accounting.DefaultAccounting(m.BaseCurrency, m.VolumePrecision)
|
a := accounting.DefaultAccounting(m.BaseCurrency, m.VolumePrecision)
|
||||||
a.Format = "%v %s"
|
a.Format = "%v %s"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user