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

Update all orders - at depth - when account balance change #53

Open
mdyring opened this issue Mar 18, 2021 · 0 comments
Open

Update all orders - at depth - when account balance change #53

mdyring opened this issue Mar 18, 2021 · 0 comments
Assignees
Labels
bug Something isn't working consensus-breaking

Comments

@mdyring
Copy link
Contributor

mdyring commented Mar 18, 2021

Describe the bug
Code at

// Update any orders that can no longer be filled with the account's balance.

.. does not take into consideration that there may exist multiple orders for a unique (src, dst).
The sum of SourceRemaining for the same (src, dst) should not exceed the available account balance.

The current implementation does not handle this case, but only deals with it on order creation:

// Ensure that the market is not showing "phantom liquidity" by rejecting multiple orders in an instrument based on the same balance.

How to reproduce

  • With an account balance of 10 eEUR.
  • Create 10 orders selling 1 eEUR for e.g. 1 eCHF (src: eEUR, dst: eCHF)
  • Send 7 eEUR from the account, reducing the balance to 3 eEUR.
  • 10 orders will remain with unchanged sourceRemaining, as the 3 eEUR balance is still above 1 eEUR for each individual order.

Expected behavior
Invariant: The sum of the sourceRemaining for identical (src, dst) orders should not exceed the spendable account balance.

Working through the orders in reverse distance from the best price, i.e. "orders the farthest away from the best price first", should have they sourceRemaining reduced and canceled until the above invariant holds.

@mdyring mdyring added bug Something isn't working consensus-breaking labels Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working consensus-breaking
Projects
None yet
Development

No branches or pull requests

2 participants