Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Inconsistent sorting of call orders between matching against a limit order and a force settle order #343

Closed
abitmore opened this issue Jul 31, 2017 · 2 comments

Comments

@abitmore
Copy link
Member

Call orders will be sorted then matched against other orders in two scenarios:

  1. when being margin called
  2. when being force settled

However, the sorting methods used in these two scenarios are different.

For margin calls, it's by_price (code):

const auto& call_price_index = call_index.indices().get<by_price>();

It's the call price when the short position was updated last time. It won't change.

For force settlements, it's by_collateral (code):

auto& call_index = get_index_type<call_order_index>().indices().get<by_collateral>();

It's the real-time collateral ratio of the call order. It changes every time when the order is partially filled.

The consequence: when a call order is partially filled, no matter if it's margin called or force settled, its real collateral ratio is increased, so it will have less chance to be matched against a force settlement order again; however, it will still be margin called at the initial call price.

Personally I think the by_collateral sorting is fairer and we should use it in both scenarios.

@pmconrad
Copy link
Contributor

I agree that by_collateral is the better choice in both cases. I was actually surprised to find that the margin call code didn't update the call price after a partial fill when I wrote my recent explanation of margin calls.

OTOH I think this is a relatively minor issue. I'm therefore unsure whether this should be changed. In any case it's not a bugfix but a change of behaviour. IMO this means that the change requires shareholder approval.

@oxarbitrage oxarbitrage added this to the Roadmap to hardfork milestone Aug 13, 2017
@abitmore abitmore modified the milestones: Hardfork - Bugs , Future Consensus-Changing Release Nov 27, 2017
@abitmore abitmore modified the milestones: Future Consensus-Changing Release, 201803 - Consensus Changing Release Dec 23, 2017
@abitmore abitmore added the bug label Jan 29, 2018
@abitmore abitmore self-assigned this Jan 29, 2018
abitmore added a commit that referenced this issue Feb 3, 2018
For:
* #338 Margin call order fills at price of matching limit_order
* #343 Inconsistent sorting of call orders between matching against a limit order and a force settle order
* #453 Multiple limit order and call order matching issue
* #606 Undercollateralized short positions should be called regardless of asks
abitmore added a commit that referenced this issue Feb 6, 2018
abitmore added a commit that referenced this issue Feb 7, 2018
abitmore added a commit that referenced this issue Feb 8, 2018
abitmore added a commit that referenced this issue Apr 7, 2018
abitmore added a commit that referenced this issue Apr 7, 2018
For:
* #338 Margin call order fills at price of matching limit_order
* #343 Inconsistent sorting of call orders between matching against a limit order and a force settle order
* #453 Multiple limit order and call order matching issue
* #606 Undercollateralized short positions should be called regardless of asks
abitmore added a commit that referenced this issue Apr 7, 2018
abitmore added a commit that referenced this issue Apr 7, 2018
@abitmore
Copy link
Member Author

Done with #829.

abitmore added a commit that referenced this issue Sep 13, 2018
Note: this should not break compatibility in production because the result should be the same after hard fork #343.
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants