bollpp: fix order quantity

This commit is contained in:
c9s 2021-10-18 00:56:22 +08:00
parent 0bd32094ee
commit d6b707c832
2 changed files with 8 additions and 10 deletions

View File

@ -1,16 +1,16 @@
---
exchangeStrategies:
- on: binance
- on: max
bollpp:
symbol: ETHUSDT
interval: 1m
quantity: 0.01
interval: 5m
quantity: 0.005
# spread: sell price = middle price + spread, buy price = middle price - spread
# you need to ensure that the spread can cover your trading fee
# for example, the trading fee on binance is 0.075%, so the total fee of your buy/sell orders is 0.075% * 2 = 0.14%
spread: 0.05%
spread: 0.01%
defaultBollinger:
interval: "5m"
window: 21

View File

@ -210,8 +210,7 @@ func (s *Strategy) placeOrders(ctx context.Context, orderExecutor bbgo.OrderExec
Quantity: s.Quantity.Float64(),
Price: askPrice.Float64(),
Market: s.market,
// TimeInForce: "GTC",
GroupID: s.groupID,
GroupID: s.groupID,
}
buyOrder := types.SubmitOrder{
Symbol: s.Symbol,
@ -220,20 +219,19 @@ func (s *Strategy) placeOrders(ctx context.Context, orderExecutor bbgo.OrderExec
Quantity: s.Quantity.Float64(),
Price: bidPrice.Float64(),
Market: s.market,
// TimeInForce: "GTC",
GroupID: s.groupID,
GroupID: s.groupID,
}
var submitOrders []types.SubmitOrder
minQuantity := fixedpoint.NewFromFloat(s.market.MinQuantity)
if base > -minQuantity && base < minQuantity {
if base == 0 || base.Abs() < minQuantity {
submitOrders = append(submitOrders, sellOrder, buyOrder)
} else if base > minQuantity {
sellOrder.Quantity = base.Float64()
submitOrders = append(submitOrders, sellOrder)
} else if base < -minQuantity {
buyOrder.Quantity = base.Float64()
buyOrder.Quantity = base.Abs().Float64()
submitOrders = append(submitOrders, buyOrder)
}