Skip to content

Commit

Permalink
Merge pull request c9s#991 from andycheng123/fix/risk
Browse files Browse the repository at this point in the history
fix/risk: remove balance check in CalculateBaseQuantity()
  • Loading branch information
c9s authored Oct 17, 2022
2 parents 09c85d3 + d350806 commit 79c93e9
Showing 1 changed file with 0 additions and 6 deletions.
6 changes: 0 additions & 6 deletions pkg/bbgo/risk.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ func CalculateBaseQuantity(session *ExchangeSession, market types.Market, price,
}

baseBalance, hasBaseBalance := session.Account.Balance(market.BaseCurrency)
quoteBalance, _ := session.Account.Balance(market.QuoteCurrency)
balances := session.Account.Balances()

usingLeverage := session.Margin || session.IsolatedMargin || session.Futures || session.IsolatedFutures
Expand Down Expand Up @@ -321,12 +320,7 @@ func CalculateBaseQuantity(session *ExchangeSession, market types.Market, price,
}

if session.Futures || session.IsolatedFutures {
// TODO: get mark price here
maxPositionQuantity := risk.CalculateMaxPosition(price, totalUsdValue, leverage)
requiredPositionCost := risk.CalculatePositionCost(price, price, maxPositionQuantity, leverage, types.SideTypeSell)
if quoteBalance.Available.Compare(requiredPositionCost) < 0 {
return maxPositionQuantity, fmt.Errorf("margin total usd value %f is not enough, can not submit order", totalUsdValue.Float64())
}

return maxPositionQuantity, nil
}
Expand Down

0 comments on commit 79c93e9

Please sign in to comment.