From 40129242094782f6e87e9a61e23943d73670ba38 Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 11 Apr 2018 07:47:54 -0400 Subject: [PATCH] bsip38: update rounding --- bsip-0038.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bsip-0038.md b/bsip-0038.md index 093681f..62dca9d 100644 --- a/bsip-0038.md +++ b/bsip-0038.md @@ -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).