mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Improve bollgrid strategy's balance check and quote calculation
This commit is contained in:
parent
776cd95955
commit
d22a8e9c63
|
@ -175,11 +175,11 @@ func (s *Strategy) updateAskOrders(orderExecutor bbgo.OrderExecutor, session *bb
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) placeGridOrders(orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) {
|
func (s *Strategy) placeGridOrders(orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) {
|
||||||
quoteCurrency := s.Market.QuoteCurrency
|
|
||||||
balances := session.Account.Balances()
|
balances := session.Account.Balances()
|
||||||
|
quoteBalance := balances[s.Market.QuoteCurrency].Available.Float64()
|
||||||
|
baseBalance := balances[s.Market.BaseCurrency].Available.Float64()
|
||||||
|
|
||||||
balance, ok := balances[quoteCurrency]
|
if quoteBalance <= 0 && baseBalance <= 0 {
|
||||||
if !ok || balance.Available <= 0 {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,22 +222,6 @@ func (s *Strategy) placeGridOrders(orderExecutor bbgo.OrderExecutor, session *bb
|
||||||
side = types.SideTypeBuy
|
side = types.SideTypeBuy
|
||||||
}
|
}
|
||||||
|
|
||||||
// trend up
|
|
||||||
switch side {
|
|
||||||
|
|
||||||
case types.SideTypeBuy:
|
|
||||||
if ema7.Last() > ema25.Last()*1.001 && ema25.Last() > ema99.Last()*1.0005 {
|
|
||||||
log.Infof("all ema lines trend up, skip buy")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
case types.SideTypeSell:
|
|
||||||
if ema7.Last() < ema25.Last()*(1-0.004) && ema25.Last() < ema99.Last()*(1-0.0005) {
|
|
||||||
log.Infof("all ema lines trend down, skip sell")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
order := types.SubmitOrder{
|
order := types.SubmitOrder{
|
||||||
Symbol: s.Symbol,
|
Symbol: s.Symbol,
|
||||||
Side: side,
|
Side: side,
|
||||||
|
@ -247,6 +231,32 @@ func (s *Strategy) placeGridOrders(orderExecutor bbgo.OrderExecutor, session *bb
|
||||||
Price: price,
|
Price: price,
|
||||||
TimeInForce: "GTC",
|
TimeInForce: "GTC",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch side {
|
||||||
|
|
||||||
|
case types.SideTypeBuy:
|
||||||
|
if ema7.Last() > ema25.Last()*1.001 && ema25.Last() > ema99.Last()*1.0005 {
|
||||||
|
log.Infof("all ema lines trend up, skip buy")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if quoteBalance < order.Quantity {
|
||||||
|
log.Infof("quote balance %f is not enough, stop generating buy orders", quoteBalance)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
quoteBalance -= order.Quantity
|
||||||
|
|
||||||
|
case types.SideTypeSell:
|
||||||
|
if ema7.Last() < ema25.Last()*(1-0.004) && ema25.Last() < ema99.Last()*(1-0.0005) {
|
||||||
|
log.Infof("all ema lines trend down, skip sell")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if baseBalance < order.Quantity {
|
||||||
|
log.Infof("base balance %f is not enough, stop generating sell orders", baseBalance)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
baseBalance -= order.Quantity
|
||||||
|
}
|
||||||
|
|
||||||
log.Infof("submitting order: %s", order.String())
|
log.Infof("submitting order: %s", order.String())
|
||||||
orders = append(orders, order)
|
orders = append(orders, order)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user