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

[Bug]: EstimatePosition collateral increase estimate #10852

Closed
Sohill-Patel opened this issue Mar 8, 2024 · 1 comment · Fixed by #10865
Closed

[Bug]: EstimatePosition collateral increase estimate #10852

Sohill-Patel opened this issue Mar 8, 2024 · 1 comment · Fixed by #10865
Assignees
Labels

Comments

@Sohill-Patel
Copy link
Contributor

Problem encountered

slack conversation
https://vegaprotocol.slack.com/archives/CAHA5EX0F/p1709906805588419

Ac

In isolated margin mode: open a position so that open volume is non-zero and there are some open orders. Query the EstimatePosition with the details of that position. The collateral increase estimate should be 0. No query the EstimatePosition with a higher margin factor. The collateral increase estimate should be positive and equal to the decrease in the general account balance after margin factor is updated for the party. Now lower the margin factor below the value the test originally started with and repeat. The collateral increase estimate should be negative and equal to the decrease in the general account balance (the balance should increase). (0013-NP-POSE-010)

The test requests for 3 estimates

  • base estimate
  • increase margin_factor
  • decrease margin_factor
    and at each estimate the test updates the traders margin_factor and compares actual general account diffs with the estimate

Last part of this ac is to check the collateral increase estimate equals the decrease in the general account balance however this is where there is a divergence

Observed behaviour

the estimate returned from api and the actual diff between general account balance is significantly different

assert gen_acc_diff2 == int(
            best_case3
        ), f"diff of {updated_gen_acc2} - {gen_acc} does not match collateral increase estimate"
E       AssertionError: diff of 99997066940000000000000000 - 99998435940000000000000000 does not match collateral increase estimate
E       assert -1369000000000000000000 == -392000000000000000000

Expected behaviour

api estimate and actual diff should be the same

Steps to reproduce

1. run the test `test_collateral_estimate_isolated_margin` on branch `est-margin-ac`

Software version

dev branch

Failing test

test_collateral_estimate_isolated_margin

Jenkins run

https://jenkins.vega.rocks/job/common/job/system-tests-wrapper/48220/testReport/junit/tests.margins/margins_test/test_collateral_estimate_isolated_margin/

Configuration used

No response

Relevant log output

No response

@witgaw
Copy link
Member

witgaw commented Mar 8, 2024

More fundamentally, it doesn't seem to be possible (at least not via the UI) to ever lower the per-market margin account balance in isolated mode (except for cancelling the order), going back an forth between say 40x and 20x leverage only keeps increasing the margin account balance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants