bsip38: update rounding

This commit is contained in:
abitmore 2018-04-11 07:47:54 -04:00
parent 44818ec0b6
commit 4012924209

View file

@ -103,9 +103,6 @@ The result is a rational number as well.
As described in [BSIP 35](bsip-0035.md), at last we need to convert the
rational numbers to integers, so rounding is involved.
Since maximum debt to cover is primarily used in order matching algorithm, we
will only focus on it here.
When calculating maximum debt to cover, the goal is to go over the specified
target but not go too far beyond.
That said, if a short position got matched with a big limit order, after
@ -115,6 +112,19 @@ fraction, need to plus it by one Satoshi; otherwise, need to round it up.
An effectively same approach is to round down then add one Satoshi onto the
result.
With `max_debt_to_cover` in integer, `max_amount_to_sell` in integer should be
calculated as:
```
max_amount_to_sell = round_up(max_debt_to_cover / match_price)
```
Then adjust `max_debt_to_cover` to be more accurate with:
```
max_debt_to_cover = round_down(max_amount_to_sell * match_price)
```
## Rounding on Order Matching, and Edge Cases
Rounding rules about order matching are defined in [BSIP 35](bsip-0035.md).