Skip to content

Commit

Permalink
bbgo: check base balance only for long position
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Sep 11, 2022
1 parent b805b19 commit db94b26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/bollmaker.yaml
Expand Up @@ -195,7 +195,7 @@ exchangeStrategies:
tradeInBand: true

# buyBelowNeutralSMA: when this set, it will only place buy order when the current price is below the SMA line.
buyBelowNeutralSMA: false
buyBelowNeutralSMA: true

exits:

Expand Down
9 changes: 7 additions & 2 deletions pkg/bbgo/order_executor_general.go
Expand Up @@ -272,8 +272,13 @@ func (e *GeneralOrderExecutor) ClosePosition(ctx context.Context, percentage fix
}

// check base balance and adjust the close position order
if baseBalance, ok := e.session.Account.Balance(e.position.Market.BaseCurrency); ok {
submitOrder.Quantity = fixedpoint.Min(submitOrder.Quantity, baseBalance.Available)
if e.position.IsLong() {
if baseBalance, ok := e.session.Account.Balance(e.position.Market.BaseCurrency); ok {
submitOrder.Quantity = fixedpoint.Min(submitOrder.Quantity, baseBalance.Available)
}
if submitOrder.Quantity.IsZero() {
return fmt.Errorf("insufficient base balance, can not sell: %+v", submitOrder)
}
}

tagStr := strings.Join(tags, ",")
Expand Down

0 comments on commit db94b26

Please sign in to comment.