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 continue
} }
spread := ticker.Sell.Sub(ticker.Buy)
// changeQuantity > 0 = buy // changeQuantity > 0 = buy
// changeQuantity < 0 = sell // changeQuantity < 0 = sell
q := changeQuantity.Abs() q := changeQuantity.Abs()
@ -135,8 +137,8 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
price := ticker.Sell price := ticker.Sell
if taker { if taker {
price = ticker.Sell price = ticker.Sell
} else if ticker.Buy.Add(market.TickSize).Compare(ticker.Sell) < 0 { } else if spread.Compare(market.TickSize) > 0 {
price = ticker.Buy.Add(market.TickSize) price = ticker.Sell.Sub(market.TickSize)
} else { } else {
price = ticker.Buy price = ticker.Buy
} }
@ -174,14 +176,14 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
price := ticker.Buy price := ticker.Buy
if taker { if taker {
price = ticker.Buy price = ticker.Buy
} else if ticker.Sell.Add(market.TickSize.Neg()).Compare(ticker.Buy) < 0 { } else if spread.Compare(market.TickSize) > 0 {
price = ticker.Sell.Add(market.TickSize.Neg()) price = ticker.Buy.Add(market.TickSize)
} else { } else {
price = ticker.Sell price = ticker.Sell
} }
if market.IsDustQuantity(q, price) { 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 return nil, nil
} }