mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
xalign: apply market.GreaterThanMinimalOrderQuantity on xalign
This commit is contained in:
parent
8b6a8aeb7b
commit
c3cce05bdd
|
@ -145,8 +145,9 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
|
||||||
// changeQuantity < 0 = sell
|
// changeQuantity < 0 = sell
|
||||||
q := changeQuantity.Abs()
|
q := changeQuantity.Abs()
|
||||||
|
|
||||||
|
// a fast filtering
|
||||||
if q.Compare(market.MinQuantity) < 0 {
|
if q.Compare(market.MinQuantity) < 0 {
|
||||||
log.Infof("skip dust quantity: %f", q.Float64())
|
log.Debugf("skip dust quantity: %f", q.Float64())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,11 +156,6 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
|
||||||
switch side {
|
switch side {
|
||||||
|
|
||||||
case types.SideTypeBuy:
|
case types.SideTypeBuy:
|
||||||
quoteBalance, ok := session.Account.Balance(quoteCurrency)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
price := ticker.Sell
|
price := ticker.Sell
|
||||||
if taker {
|
if taker {
|
||||||
price = ticker.Sell
|
price = ticker.Sell
|
||||||
|
@ -169,6 +165,11 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
|
||||||
price = ticker.Buy
|
price = ticker.Buy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quoteBalance, ok := session.Account.Balance(quoteCurrency)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
requiredQuoteAmount := q.Mul(price)
|
requiredQuoteAmount := q.Mul(price)
|
||||||
requiredQuoteAmount = requiredQuoteAmount.Round(market.PricePrecision, fixedpoint.Up)
|
requiredQuoteAmount = requiredQuoteAmount.Round(market.PricePrecision, fixedpoint.Up)
|
||||||
if requiredQuoteAmount.Compare(quoteBalance.Available) > 0 {
|
if requiredQuoteAmount.Compare(quoteBalance.Available) > 0 {
|
||||||
|
@ -176,24 +177,28 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if market.IsDustQuantity(q, price) {
|
if quantity, ok := market.GreaterThanMinimalOrderQuantity(side, price, requiredQuoteAmount); ok {
|
||||||
log.Infof("%s ignore dust quantity: %f", currency, q.Float64())
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
q = market.AdjustQuantityByMinNotional(q, price)
|
|
||||||
|
|
||||||
return session, &types.SubmitOrder{
|
return session, &types.SubmitOrder{
|
||||||
Symbol: symbol,
|
Symbol: symbol,
|
||||||
Side: side,
|
Side: side,
|
||||||
Type: types.OrderTypeLimit,
|
Type: types.OrderTypeLimit,
|
||||||
Quantity: q,
|
Quantity: quantity,
|
||||||
Price: price,
|
Price: price,
|
||||||
Market: market,
|
Market: market,
|
||||||
TimeInForce: "GTC",
|
TimeInForce: types.TimeInForceGTC,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case types.SideTypeSell:
|
case types.SideTypeSell:
|
||||||
|
price := ticker.Buy
|
||||||
|
if taker {
|
||||||
|
price = ticker.Buy
|
||||||
|
} else if spread.Compare(market.TickSize) > 0 {
|
||||||
|
price = ticker.Buy.Add(market.TickSize)
|
||||||
|
} else {
|
||||||
|
price = ticker.Sell
|
||||||
|
}
|
||||||
|
|
||||||
baseBalance, ok := session.Account.Balance(currency)
|
baseBalance, ok := session.Account.Balance(currency)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
|
@ -204,28 +209,16 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
price := ticker.Buy
|
if quantity, ok := market.GreaterThanMinimalOrderQuantity(side, price, q); ok {
|
||||||
if taker {
|
|
||||||
price = ticker.Buy
|
|
||||||
} 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 ignore dust quantity: %f", currency, q.Float64())
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return session, &types.SubmitOrder{
|
return session, &types.SubmitOrder{
|
||||||
Symbol: symbol,
|
Symbol: symbol,
|
||||||
Side: side,
|
Side: side,
|
||||||
Type: types.OrderTypeLimit,
|
Type: types.OrderTypeLimit,
|
||||||
Quantity: q,
|
Quantity: quantity,
|
||||||
Price: price,
|
Price: price,
|
||||||
Market: market,
|
Market: market,
|
||||||
TimeInForce: "GTC",
|
TimeInForce: types.TimeInForceGTC,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user