-
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
1.7.18: fix: update sl/tp percentage diff calculation to use max(leverage, 1) #354
1.7.18: fix: update sl/tp percentage diff calculation to use max(leverage, 1) #354
Conversation
6de153e
to
3784b8a
Compare
src/commonMain/kotlin/exchange.dydx.abacus/calculator/TriggerOrdersInputCalculator.kt
Outdated
Show resolved
Hide resolved
tests please |
@@ -89,13 +90,14 @@ internal class TriggerOrdersInputCalculator(val parser: ParserProtocol) { | |||
val positionSide = parser.asString(parser.value(position, "resources.indicator.current")) | |||
val positionSize = parser.asDouble(parser.value(position, "size.current"))?.abs() ?: return modified | |||
val notionalTotal = parser.asDouble(parser.value(position, "notionalTotal.current")) ?: return modified | |||
val leverage = parser.asDouble(parser.value(position, "leverage.current"))?.abs() ?: return modified | |||
val leverage = requireNotNull(parser.asDouble(parser.value(position, "leverage.current"))) { "leverage was null" } |
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.
chatted w @prashanDYDX let's revert requireNotNull
it's not with 100% certainty that leverage.current
is non-null and requireNotNull
throws an error which would break in semi-valid cases.
null, | ||
) | ||
|
||
val leverage = 1.0; |
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.
shouldnt this be less than 1?
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.
oh but for the calculations, they should be 1 (and I'm just using this variable for calculations)
} | ||
|
||
@Test | ||
fun testLessThanZeroLeverageInputs() { |
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.
did you mean less than one?
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.
hahahaaaaaaa yes i do
leverage of < 1 made our percentage calculations really funky. After chatting, it made sense to take max(leverage, 1) since <1 leverage is effectively trading with 1 leverage. See vid of update in action:
modifiedPercentageDIff.mov