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

Add BSIP 34: Always Trigger Margin Call When Call Price Above Or At Price Feed #58

Merged
merged 2 commits into from
Feb 22, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions bsip-0034.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
BSIP: 0034
Title: Always Trigger Margin Call When Call Price Above Or At Price Feed
Author: Abit More <https://github.com/abitmore>
Status: Draft
Type: Protocol
Created: 2018-02-18
Discussion: https://github.com/bitshares/bitshares-core/issues/606
Replaces: -
Worker: To be done

# Abstract
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of this abstract belongs in the Motivation section IMO.


To avoid ambiguity, in this article, all prices are in terms of
`debt asset / collateral asset`, aka how much debt asset per collateral
asset. A bid is an order to buy collateral asset with debt asset.

Generally, a short position may be margin called when its collateral ratio is
below or equal to maintenance collateral ratio (MCR).

However, to calculate collateral ratio, a fair collateral price is needed.

In BitShares, there are two data sources can be used to decide the fair
collateral price:
* the internal market
* the price feeds

Currently, both data sources are used. Specifically, collateral price is decided
as the higher one between the highest bid price on the internal market and the
median price feed. That said, when a short position's collateral ratio has
fallen to below or equal to MCR according to median price feed (in this case,
call price of the short position is above or equal to median price feed), if
there is a bid on the market with high price, the short position won't be margin
called.

This mechanism has led to certain confusion and anger among market participants.
* there are often orders with overlapping price on the book but didn't fill
* there are often short positions selling collaterals with low prices, but
traders are unable to buy at those prices
* it often causes borrowers to sell collaterals at a low price when have chances
to sell at higher price
* market manipulators / arbitrage traders have more chances to force borrowers
to sell collaterals at lower price

This BSIP proposes a new behavior to improve the situation: derive the fair
collateral price only from price feeds.

# Motivation

Make the exchange system easier to understand and more user-friendly.

# Rationale

Since price feeds are provided by a set of chosen producers, the median price
feed is usually considered trustworthy. On the other hand, instant market
price is not as reliable, especially for the markets with poor depth, so it's
a rather limited supplement for calculating collateral price. Depth of internal
markets could be greatly improved in the future, however price feed producers
Copy link
Contributor

Choose a reason for hiding this comment

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

Bad idea, please remove the last sentence of this paragraph. (Or leave it in if you disagree, this PR is not about discussing the BSIP.)

can always adjust their algorithm to include internal market data.

At this moment, changing the rule to only use median price feed will clear away
the confusion the end users may have, while still keeping the derived collateral
price fair to an extent.

After this change is done, placing a new limit order will no longer trigger a
margin call, cancelling a limit order or expiring a limit order will no longer
trigger a margin call as well, that means we don't need to check for new margin
calls nor black swan events in those scenarios, so we'll gain a side benefit on
performance.

# Specifications

In `check_call_orders(...)` function of `database` class, when matching a call
order with a limit order, there is a check:
`if( match_price > ~call_itr->call_price )`, when the result is `true`,
processing will be ended and `margin_called` will be returned.
Need to skip the check and the following `return` action.

In `do_apply(...)` function of `limit_order_cancel_evaluator` class, and
similar code blocks after a limit order object is removed, no longer need to
call `check_call_orders(...)` function of `database` class.

# Discussion

[to be added if any]

# Summary for Shareholders

[to be added if any]

# Copyright

This document is placed in the public domain.

# See Also

* https://github.com/bitshares/bitshares-core/issues/606
* https://bitsharestalk.org/index.php?topic=25926.0