-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix balancePercent calculations for trades on opposite side of current position #650
Conversation
if (freeCollateral <= Numeric.double.ZERO) { | ||
return Numeric.double.ZERO | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to add a non-zero check for tradeLeverage
as well?
@@ -558,7 +622,7 @@ internal class TradeInputMarketOrderCalculator() { | |||
break@orderbookLoop | |||
} | |||
} | |||
val balancePercentTotal = (usdcSizeTotal / tradeLeverage) / freeCollateral | |||
val balancePercentTotal = calculateBalancePercentFromUsdcSize(usdcSize = usdcSizeTotal, freeCollateral = freeCollateral, positionSize = positionSizeNotional, tradeLeverage = tradeLeverage, isTradeSameSide = isTradeSameSide) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im surprised spotless
doesn't format this to multiple lines
@@ -118,11 +119,28 @@ internal class TradeInputMarketOrderCalculator() { | |||
maxMarketLeverage | |||
} | |||
|
|||
val positions = subaccount.openPositions | |||
val marketId = market?.perpetualMarket?.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like you are getting marketId
from trade.marketId
in the non-typed TradeInputCalculator
. I'm assuming its interchangeable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yeah - they should be interchangeable, but lemme make them consistent for easier to read reasons
fixed a couple bugs with balancePercent calculations. math will be the end of me I swear
proof of concept help:
tada.mov