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

Matching Engine: swapped with peer order, should have swapped with own order #1206

Closed
kilrau opened this issue Sep 7, 2019 · 1 comment · Fixed by #1454
Closed

Matching Engine: swapped with peer order, should have swapped with own order #1206

kilrau opened this issue Sep 7, 2019 · 1 comment · Fixed by #1454
Assignees
Labels
bug Something isn't working order book P2 mid priority

Comments

@kilrau
Copy link
Contributor

kilrau commented Sep 7, 2019

Background

Matching engine should prio matching with own orders. It did not, matched with peer orders instead.

Your environment

  • version of xud: master
  • which operating system (uname -a on *Nix):
  • version of btcd, bitcoind, ltcd, litecoind, geth, parity, raiden, lnd or other chain backend: simnet
  • any other relevant environment details: simnet

Steps to reproduce

Trading pair: WETH/BTC
┌───────────────────────────────────────┬───────────────────────────────────────┐
│ Buy                                   │ Sell                                  │
├───────────────────┬───────────────────┼───────────────────┬───────────────────┤
│ Quantity          │ Price             │ Price             │ Quantity          │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 3.1               │ 0.021             │ 0.023             │ 2.1               │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 15.5              │ 0.02              │ 0.024             │ 13                │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 18                │ 0.019             │ 0.025             │ 15.6              │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 21.25             │ 0.018             │ 0.026             │ 18.1              │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 24                │ 0.017             │ 0.027             │ 22.3              │
└───────────────────┴───────────────────┴───────────────────┴───────────────────┘
simnet > buy 0.1 weth/btc 0.021
no matches found
remaining 0.1 WETH entered the order book as fbbbdc20-d15c-11e9-9107-7d92664f3f46
simnet > orderbook

Trading pair: WETH/BTC
┌───────────────────────────────────────┬───────────────────────────────────────┐
│ Buy                                   │ Sell                                  │
├───────────────────┬───────────────────┼───────────────────┬───────────────────┤
│ Quantity          │ Price             │ Price             │ Quantity          │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 3.2               │ 0.021             │ 0.023             │ 2.1               │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 15.5              │ 0.02              │ 0.024             │ 13                │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 18                │ 0.019             │ 0.025             │ 15.6              │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 21.25             │ 0.018             │ 0.026             │ 18.1              │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 24                │ 0.017             │ 0.027             │ 22.3              │
└───────────────────┴───────────────────┴───────────────────┴───────────────────┘
simnet > sell 0.1 weth/btc 0.021
swapped 0.1 WETH with peer order 1bc42180-d153-11e9-9d10-97467125afef
simnet > sell 0.1 weth/btc 0.021
swapped 0.1 WETH with peer order 1bc42180-d153-11e9-9d10-97467125afef
simnet > orderbook

Trading pair: WETH/BTC
┌───────────────────────────────────────┬───────────────────────────────────────┐
│ Buy                                   │ Sell                                  │
├───────────────────┬───────────────────┼───────────────────┬───────────────────┤
│ Quantity          │ Price             │ Price             │ Quantity          │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 3                 │ 0.021             │ 0.023             │ 2.1               │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 15.5              │ 0.02              │ 0.024             │ 13                │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 18                │ 0.019             │ 0.025             │ 15.6              │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 21.25             │ 0.018             │ 0.026             │ 18.1              │
├───────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 24                │ 0.017             │ 0.027             │ 22.3              │
└───────────────────┴───────────────────┴───────────────────┴───────────────────┘
simnet > listorders

Trading pair: WETH/BTC
┌────────────────────────────────────────────────────┬────────────────────────────────────────────────────┐
│ Buy                                                │ Sell                                               │
├───────────────────┬───────────────────┬────────────┼───────────────────┬───────────────────┬────────────┤
│ Quantity          │ Price             │ Own Order  │ Quantity          │ Price             │ Own Order  │
├───────────────────┼───────────────────┼────────────┼───────────────────┼───────────────────┼────────────┤
│ 0.1               │ 0.021             │ X          │ 2.1               │ 0.023             │            │
├───────────────────┼───────────────────┼────────────┼───────────────────┼───────────────────┼────────────┤
│ 2.9               │ 0.021             │            │ 13                │ 0.024             │            │
├───────────────────┼───────────────────┼────────────┼───────────────────┼───────────────────┼────────────┤
│ 15.5              │ 0.02              │            │ 15.6              │ 0.025             │            │
├───────────────────┼───────────────────┼────────────┼───────────────────┼───────────────────┼────────────┤
│ 18                │ 0.019             │            │ 18.1              │ 0.026             │            │
├───────────────────┼───────────────────┼────────────┼───────────────────┼───────────────────┼────────────┤
│ 21.25             │ 0.018             │            │ 22.3              │ 0.027             │            │
├───────────────────┼───────────────────┼────────────┼───────────────────┼───────────────────┼────────────┤
│ 24                │ 0.017             │            │                   │                   │            │
└───────────────────┴───────────────────┴────────────┴───────────────────┴───────────────────┴────────────┘
simnet > 

Expected behaviour

Matching engine should have matched with own order

Actual behaviour

Matching engine matched with peer order

@kilrau kilrau added the bug Something isn't working label Sep 7, 2019
@kilrau kilrau assigned ghost Sep 7, 2019
@kilrau
Copy link
Contributor Author

kilrau commented Oct 9, 2019

Very similar: #1113

@kilrau kilrau assigned moshababo and unassigned ghost Oct 9, 2019
@kilrau kilrau added the P2 mid priority label Oct 9, 2019
@kilrau kilrau assigned rsercano and unassigned moshababo Oct 9, 2019
@kilrau kilrau assigned sangaman and unassigned LePremierHomme Apr 1, 2020
sangaman added a commit that referenced this issue Apr 2, 2020
This fixes the matching engine order book priority to prefer own orders
over peer orders when two orders have the same price. Previously, the
engine would take whichever order was seen first. This is now only
considered if two given orders at the same price point are either both
own orders or both peer orders.

Fixes #1206.
sangaman added a commit that referenced this issue Apr 2, 2020
This fixes the matching engine order book priority to prefer own orders
over peer orders when two orders have the same price. Previously, the
engine would take whichever order was seen first. This is now only
considered if two given orders at the same price point are either both
own orders or both peer orders.

Fixes #1206.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working order book P2 mid priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants