Skip to content

Commit

Permalink
support: add minBaseAssetBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jun 17, 2021
1 parent df7c416 commit 58a1e85
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/strategy/support/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Strategy struct {
ResistanceMinVolume fixedpoint.Value `json:"resistanceMinVolume"`
ResistanceTakerBuyRatio fixedpoint.Value `json:"resistanceTakerBuyRatio"`


MinBaseAssetBalance fixedpoint.Value `json:"minBaseAssetBalance"`
// Max BaseAsset balance to buy
MaxBaseAssetBalance fixedpoint.Value `json:"maxBaseAssetBalance"`
MinQuoteAssetBalance fixedpoint.Value `json:"minQuoteAssetBalance"`
Expand Down Expand Up @@ -160,8 +162,16 @@ func (s *Strategy) calculateQuantity(session *bbgo.ExchangeSession, side types.S
quantity = fixedpoint.NewFromFloat(qf)
}

if side == types.SideTypeBuy {
baseBalance, _ := session.Account.Balance(s.Market.BaseCurrency)

baseBalance, _ := session.Account.Balance(s.Market.BaseCurrency)
if side == types.SideTypeSell {
// quantity = bbgo.AdjustQuantityByMaxAmount(quantity, closePrice, quota)
if s.MinBaseAssetBalance > 0 && (baseBalance.Total() - quantity) < s.MinBaseAssetBalance {
quota := baseBalance.Available - s.MinBaseAssetBalance
quantity = bbgo.AdjustQuantityByMaxAmount(quantity, closePrice, quota)
}

} else if side == types.SideTypeBuy {
if s.MaxBaseAssetBalance > 0 && baseBalance.Total()+quantity > s.MaxBaseAssetBalance {
quota := s.MaxBaseAssetBalance - baseBalance.Total()
quantity = bbgo.AdjustQuantityByMaxAmount(quantity, closePrice, quota)
Expand Down

0 comments on commit 58a1e85

Please sign in to comment.