fix: partial cancelation based on available liquidity #235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reported Issue:
In a matching approach introduced by v14 makers are at disadvantage when it comes to order cancelation. When the maker order gets created, its liquidity is added to
MarketLiquidities
account. If any portion of that liquidity gets matched maker order is impossible to cancel until the match gets processed. This is becauseunmatched_stake
of the maker order does not get updated (reduced in that case) till match gets post-processed while it is being used to determine amount being canceled. Since that amount can be bigger than available liquidity it leads to an error until match is processed.Expected behaviour:
A partial cancel based on available liquidity should happen, leaving enough
unmatched_stake
to be matched in post-processing.Consequences:
One of the interesting consequences of this and asynchronicity of order creation operation is that
cancel_order
endpoint partial success does not necessarily mean that at later time rest of the order cannot be canceled. It should be possible if more liquidity is added to the given liquidity price point.