-
Notifications
You must be signed in to change notification settings - Fork 91
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
program: scale down init asset weights past threshold #575
Conversation
|
||
// when orders are placed in bulk, only need to check margin on last place | ||
if options.enforce_margin_check { | ||
// Order fails if it's risk increasing and it brings the user collateral below the margin requirement | ||
let meets_initial_margin_requirement = meets_place_order_margin_requirement( | ||
meets_place_order_margin_requirement( |
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.
previously skipped if order wasn't risk increasing. now it will check maintenance if not risk increasing
2fac946
to
2289506
Compare
let risk_decreasing = worst_case_token_amount_after.unsigned_abs() | ||
<= worst_case_token_amount_before.unsigned_abs() | ||
&& order_risk_decreasing; | ||
let risk_increasing = free_collateral_contribution_after < free_collateral_contribution_before; |
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.
is it dumb to just have a function is_risk_increasing(free_collateral_contribution_before, free_collateral_contribution_after)
since i've seen this line more than once?
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.
nah, can do that
)?; | ||
|
||
// Need to recalculate weighted_token_value if user_custom_margin_ratio != 0 | ||
if user_custom_margin_ratio != 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.
should this live in the get_worst_case_token_amount
function?
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.
was thinking we don't want the user margin ratio to effect other conditional logic that depends on get_worst_case_token_amount, wdyt?
main todos are double checking all the places that have logic based on asset weights:
calc worst case base amounts
calculating which margin type to check after fill/swap
calculating max leverage order size for spot order