-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
add max leverage params #453
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,10 @@ func (m Position) IsValid(quoteTicker string) error { | |
return fmt.Errorf("position size is not valid") | ||
} | ||
|
||
if !pfPosition.PositionInstance.IsValidLeverage(params.PerpetualFutures.MaxLeverage) { | ||
return fmt.Errorf("leverage is not valid") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -50,6 +54,10 @@ func (m PerpetualFuturesPosition) IsValidPositionSize(quoteTicker string) bool { | |
return !marginMaintenanceRate.LT(sdk.OneDec()) | ||
} | ||
|
||
func (m PerpetualFuturesPositionInstance) IsValidLeverage(maxLeverage uint32) bool { | ||
return m.Leverage > 0 && m.Leverage <= maxLeverage | ||
} | ||
|
||
func UnpackPositionInstance(positionAny types.Any) (PositionInstance, error) { | ||
position := UnpackPerpetualFuturesPositionInstance(positionAny) | ||
if position != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the provided code fragment, it seems to be written in Go programming language. Here's my brief code review:
Overall, based on this code snippet, I see no obvious bug risks, and adding some inline documentation may improve the code quality even further. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code changes seem to update the One improvement suggestion would be to add more descriptive error messages that specify which validation rule failed, rather than generic error messages. This will make it easier for developers to troubleshoot issues if/when they occur. As for bug risks, without seeing the rest of the codebase it's difficult to determine whether there are any potential issues. However, as long as the parameters being passed into |
||
|
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.
The code patch adds a call to
k.GetParams(ctx)
to retrieve parameters from the storage. Otherwise, it appears to be adding validation forposition
creation usingIsValid()
method.Without seeing the full context of the code, it's hard to identify any potential bugs or improvements. However, given that this is just one method in a larger codebase, it would be helpful to ensure consistency in coding style, naming conventions, and error handling throughout the codebase. It's also important to write clear comments and commit messages to explain the purpose and intent of each change made.