Merge pull request #991 from andycheng123/fix/risk

fix/risk: remove balance check in CalculateBaseQuantity()
This commit is contained in:
Yo-An Lin 2022-10-17 15:33:10 +08:00 committed by GitHub
commit 79c93e9a0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -227,7 +227,6 @@ func CalculateBaseQuantity(session *ExchangeSession, market types.Market, price,
} }
baseBalance, hasBaseBalance := session.Account.Balance(market.BaseCurrency) baseBalance, hasBaseBalance := session.Account.Balance(market.BaseCurrency)
quoteBalance, _ := session.Account.Balance(market.QuoteCurrency)
balances := session.Account.Balances() balances := session.Account.Balances()
usingLeverage := session.Margin || session.IsolatedMargin || session.Futures || session.IsolatedFutures usingLeverage := session.Margin || session.IsolatedMargin || session.Futures || session.IsolatedFutures
@ -321,12 +320,7 @@ func CalculateBaseQuantity(session *ExchangeSession, market types.Market, price,
} }
if session.Futures || session.IsolatedFutures { if session.Futures || session.IsolatedFutures {
// TODO: get mark price here
maxPositionQuantity := risk.CalculateMaxPosition(price, totalUsdValue, leverage) 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 return maxPositionQuantity, nil
} }