xalign: fix tick size calculation

This commit is contained in:
c9s 2023-06-13 13:44:31 +08:00
parent dadf22e48f
commit 64dcef3429
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -118,6 +118,8 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
continue
}
spread := ticker.Sell.Sub(ticker.Buy)
// changeQuantity > 0 = buy
// changeQuantity < 0 = sell
q := changeQuantity.Abs()
@ -135,8 +137,8 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
price := ticker.Sell
if taker {
price = ticker.Sell
} else if ticker.Buy.Add(market.TickSize).Compare(ticker.Sell) < 0 {
price = ticker.Buy.Add(market.TickSize)
} else if spread.Compare(market.TickSize) > 0 {
price = ticker.Sell.Sub(market.TickSize)
} else {
price = ticker.Buy
}
@ -174,14 +176,14 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
price := ticker.Buy
if taker {
price = ticker.Buy
} else if ticker.Sell.Add(market.TickSize.Neg()).Compare(ticker.Buy) < 0 {
price = ticker.Sell.Add(market.TickSize.Neg())
} else if spread.Compare(market.TickSize) > 0 {
price = ticker.Buy.Add(market.TickSize)
} else {
price = ticker.Sell
}
if market.IsDustQuantity(q, price) {
log.Infof("%s dust quantity: %f", currency, q.Float64())
log.Infof("%s ignore dust quantity: %f", currency, q.Float64())
return nil, nil
}