mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bollgrid: generate the last order if balance is not enough
This commit is contained in:
parent
3becb32843
commit
4b53b3c96a
|
@ -156,17 +156,20 @@ func (s *Strategy) generateGridBuyOrders(session *bbgo.ExchangeSession) ([]types
|
||||||
if price >= currentPrice {
|
if price >= currentPrice {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// adjust buy quantity using current quote balance
|
||||||
|
quantity := bbgo.AdjustQuantityByMaxAmount(s.Quantity, price, quoteBalance.Float64())
|
||||||
order := types.SubmitOrder{
|
order := types.SubmitOrder{
|
||||||
Symbol: s.Symbol,
|
Symbol: s.Symbol,
|
||||||
Side: types.SideTypeBuy,
|
Side: types.SideTypeBuy,
|
||||||
Type: types.OrderTypeLimit,
|
Type: types.OrderTypeLimit,
|
||||||
Market: s.Market,
|
Market: s.Market,
|
||||||
Quantity: s.Quantity,
|
Quantity: quantity,
|
||||||
Price: price,
|
Price: price,
|
||||||
TimeInForce: "GTC",
|
TimeInForce: "GTC",
|
||||||
}
|
}
|
||||||
quoteQuantity := fixedpoint.NewFromFloat(order.Quantity).MulFloat64(price)
|
quoteQuantity := fixedpoint.NewFromFloat(order.Quantity).MulFloat64(price)
|
||||||
if quoteBalance < quoteQuantity {
|
if quantity < s.MinQuantity {
|
||||||
|
// don't submit this order if buy quantity is too small
|
||||||
log.Infof("quote balance %f is not enough, stop generating buy orders", quoteBalance.Float64())
|
log.Infof("quote balance %f is not enough, stop generating buy orders", quoteBalance.Float64())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -217,17 +220,20 @@ func (s *Strategy) generateGridSellOrders(session *bbgo.ExchangeSession) ([]type
|
||||||
if price <= currentPrice {
|
if price <= currentPrice {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// adjust sell quantity using current base balance
|
||||||
|
quantity := math.Min(s.Quantity, baseBalance.Float64())
|
||||||
order := types.SubmitOrder{
|
order := types.SubmitOrder{
|
||||||
Symbol: s.Symbol,
|
Symbol: s.Symbol,
|
||||||
Side: types.SideTypeSell,
|
Side: types.SideTypeSell,
|
||||||
Type: types.OrderTypeLimit,
|
Type: types.OrderTypeLimit,
|
||||||
Market: s.Market,
|
Market: s.Market,
|
||||||
Quantity: s.Quantity,
|
Quantity: quantity,
|
||||||
Price: price,
|
Price: price,
|
||||||
TimeInForce: "GTC",
|
TimeInForce: "GTC",
|
||||||
}
|
}
|
||||||
baseQuantity := fixedpoint.NewFromFloat(order.Quantity)
|
baseQuantity := fixedpoint.NewFromFloat(order.Quantity)
|
||||||
if baseBalance < baseQuantity {
|
if quantity < s.MinQuantity {
|
||||||
|
// don't submit this order if sell quantity is too small
|
||||||
log.Infof("base balance %f is not enough, stop generating sell orders", baseBalance.Float64())
|
log.Infof("base balance %f is not enough, stop generating sell orders", baseBalance.Float64())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user