# How Crypto Exchanges handle overlapping orders when self trading is disabled?

I am unsure how a typical "matching engine" handles overlapping orders (in my case, Deribit). I would be just as interested in how any crypto exchange handles the situation. The user has self-trading set to disabled (like most users).

Given the following very simple orderbook...

SELL $$504.... amount=20000.... owner=ALICE SELL$$503.... amount=15000.... owner=BOB
------
BUY. $497.... amount=15000.... owner=BOB  If BOB sends through a new GTC limit order (not post)... BUY...$505... amount=30000... owner=BOB


My understanding is if BOB had sent through an amount of 20000 or less, the order would execute entirely against ALICE and the status be set to "filled" without any errors (despite the order overlap and self-trading being set to disabled).

But what happens to BOB's new overlapping order (with amount=30000)?

(1) Rejected because BOB's order did not completely fill requested amount=30000 so an "order_overlap" error is returned and filled_amount=0.

(2) Partially filled and status set to "cancelled" but with filled_amount=20000

(3) Partially filled and status set to "open" with filled_amount=20000 with price adjusted down (to 502.50 after executing at $504.00 against ALICE) ## 1 Answer Generally in a regulated exchange, you are not allowed to skip price points. In the case you have shown, BOB's new Buy order will skip the price point at 503 and execute at$504. Therefore the order will get cancelled/expired/rejected even if the time constraint of the order is not IOC/FAK.

So in both scenarios you mentioned (whether the order quantity is 20,000 or 30,000), the regulated orders will not execute since they are skipping a price point.

The important point to remember here is that the exchanges are supposed to provide a price-time order book. Take the following scenario:

SELL ALICE 10000 @ $$503 at 17:00:00.000 UTC SELL BOB 5000 @$$503 at 17:00:00.010 UTC
SELL DAVE 1000 @ $$503 at 17:10:00.025 UTC SELL JANICE 1000 @$$504 at 16:58:00.000 UTC


In this, you can see while JANICE has sent the order earlier on, it is at the back of the queue because the price is worse. Now let's suppose BOB submits a new BUY order 11000 @ \$503, this will first match 10000 with ALICE. If self-trade-prevention is on, then it will skip BOB's own order and will match with DAVE.

Let's suppose the order size was 15000 instead. In a regulated exchange, it will match with ALICE and DAVE and the remaining 4000 will be expired.

Do note that some exchanges provide additional controls over the order such as FOK (Fill the entire order, Or kill it. No partial fills), min fill sizes etc. So depending on that your experience may slightly vary.

• This is a great answer, this is how I would expect an exchange to operate (case (2) in my question). Deribit is likely to accept the order and execute based on the scenario described (Alice, Bob, Dave, Janice). However I had a quote from Deribit's documentation originally but removed it. Based on their wording though, it seems like there is some exception case where they will not operate how you have described... which is the cause for my confusion. See the "Research" section of old question: quant.stackexchange.com/revisions/58182/1 – WhySoDifficult Sep 24 '20 at 11:32
• Have you tried contacting Deribit? – Bob Jansen Sep 24 '20 at 11:38
• Due to the question largely being academic in nature (for me personally), I would rather avoid asking them excessive questions (I have asked many other questions as well). Deribit and every crypto exchange could certainly fine-tune their advanced user documentation, I won't hold my breath on that though. It is an important question in general though for anyone building a trading bot for the share market, forex or crypto (could benefit many on quant.stackexchange). But you are probably right @BobJansen... Deribit may be the only one who knows what the exception case might be. – WhySoDifficult Sep 24 '20 at 12:35
• @WhySoDifficult I read the quote you had in the revision but it does not explicitly state about a skipping a price point. Their docmay still be talking about the Alice, Bob, Dave, Janice set up but executing Bob's contra order with only Alice and Dave and stopping and expiring the rest. The reason why the price-point-skipping is not encouraged is that usually it causes market confusion on why a certain price point wasn't cleared. It also causes issues with best-execution regulations. – Kulendra 'KJ' Janaka Sep 24 '20 at 13:06
• I noticed that you had also asked about maximising volume vs. throwing an error. Note that unless the trade volume is really low, this causes an issue with just one person's order. Given that there are many participants, that one trade may not cause a major impact to the market at all. Also refer: NASDAQ: bit.ly/3j13ake London Stock Exchange: bit.ly/3kKTT0c (3.10) ICE Futures: bit.ly/3iZNAFv – Kulendra 'KJ' Janaka Sep 24 '20 at 13:16