bsip35: adjust mechanism handling settle order

This commit is contained in:
abitmore 2018-02-20 18:16:48 +00:00
parent dceedb9d43
commit 1cf3cf894d

View file

@ -182,15 +182,23 @@ The detailed rules proposes in this BSIP (new rules highlighted):
* **if the smaller order would get nothing after the round-down, cancel it** * **if the smaller order would get nothing after the round-down, cancel it**
* when matching a limit order with a call order, in favor of call order, * when matching a limit order with a call order, in favor of call order,
round down receiving collateral amount round down receiving collateral amount
* **if the call order is receiving the whole debt (so the short position * **if the call order is receiving the whole debt amount (so the short
will be closed) but paying nothing, let it pay 1 Satoshi (round up);** position will be closed) but paying nothing, let it pay 1 Satoshi
(round up);**
* **otherwise, if the limit order would get nothing after the round-down, * **otherwise, if the limit order would get nothing after the round-down,
cancel it (it's smaller, so safe to cancel)** cancel it (it's smaller, so safe to cancel)**
* when matching a settle order with a call order, in favor of call order, * when matching a settle order with a call order, in favor of call order,
round down receiving collateral amount round down receiving collateral amount
* **if the settle order would get nothing after the round-down, give it 1 * **if the call order is receiving the whole debt amount (so the short
Satoshi (round up); after paid both side, check if a black swan event would position will be closed) but paying nothing, let it pay 1 Satoshi
be triggered by the round-up, if yes, trigger it** (round up);**
* **otherwise, if the settle order would be completely filled but would
receive nothing, cancel it;**
* **otherwise, it means both orders won't be completely filled, which may
due to hitting `maximum_force_settlement_volume`, in this case, don't fill
any one of the two orders, and stop matching for this asset at this block;**
* **that said, only round up when the call order is completely filled, so
won't trigger a black swan event, nor need to check for it.**
* when globally settling, in favor of call order, round down receiving * when globally settling, in favor of call order, round down receiving
collateral amount collateral amount
* **when the asset is not a prediction market, if a call order would pay * **when the asset is not a prediction market, if a call order would pay
@ -243,15 +251,23 @@ so the order will be cancelled later.
In `check_call_orders(...)` function of `database` class, In `check_call_orders(...)` function of `database` class,
after calculated `order_receives`, check if it is zero. after calculated `order_receives`, check if it is zero.
If the answer is `true`, If the answer is `true`,
* if `call_receives` is equal to `call_itr->debt`, set `order_receives` to 1; * if `call_receives` is equal to `call_itr->debt`, set `order_receives` to `1`;
* otherwise, skip filling and cancel the limit order. * otherwise, skip filling and cancel the limit order.
## When Matching A Settle Order With A Call Order ## When Matching A Settle Order With A Call Order
In `match( const call_order_object&, ... )` function of `database` class, In `match( const call_order_object&, ... )` function of `database` class,
after calculated `call_pays`, round up it to `1` if it is zero. after calculated `call_pays`, check if it is zero.
If the answer is `true`,
* if `call_receives` is equal to `call_debt`, set `call_pays` to `1`;
* otherwise, if `call_receives` is equal to `settle.balance`,
call `cancel_order(...)` with parameter set to `settle`,
then return a zero-amount collateral asset object;
* otherwise, return a zero-amount collateral asset object directly.
If rounded up, after filled both orders, check and allow a black swan event. After returned, need to check the amount of returned asset at where calling the
`match(...)` function, specifically, `clear_expired_orders()` function of
`database` class. If the returned amount is `0`, break out of the `while` loop.
## When Globally Settling ## When Globally Settling