Skip to content
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 exception when closing a position of > 100% margin usage #761

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

ruixhuang
Copy link
Contributor

Also adding tracking code to log client-side exceptions like this.

@ruixhuang ruixhuang marked this pull request as ready for review December 2, 2024 21:05
@@ -109,7 +109,12 @@ internal class TradeInputMarketOrderCalculator() {
val tradeSize = trade.size
val freeCollateral = subaccount?.calculated?.get(CalculationPeriod.current)?.freeCollateral

if (tradeSize != null && tradeSide != null && freeCollateral != null && freeCollateral > Numeric.double.ZERO) {
val freeCollateralCondition = if (trade.reduceOnly) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to check freeCollateral > 0 if the trade is reduceOnly.

} catch (e: Exception) {
val error = V4TransactionErrors.error(null, e.toString())
trackTransactionError("placeOrderPayload", error)
throw e
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All those "..Payload" functions are called by the web FE.. I think web code catches the exception to display the error.

Here we just catch the exception for logging and re-throw it.

Copy link
Contributor

@jaredvu jaredvu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I think web might also be logging these errors as well. will see if this ends up in duplicate logs

@ruixhuang ruixhuang merged commit f2ed254 into main Dec 3, 2024
3 checks passed
@ruixhuang ruixhuang deleted the feature/price_nil branch December 3, 2024 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants