I'm trying to understand how order fulfillment algorithm works from technical point of view.

Let's say I created an order to sell 0.8 BTC and buy 5400 XRP along with other orders to sell 0.35 BTC, 2.7 BTC, etc. On the other side, there are some traders who sell different amount of XRP to but BTC.

To be more specific, imagine:

trader1 wants to sell 0.8 BTC,

trader2 wants to sell 2.7 BTC ...

But there are no traders that are willing to sell exactly the same amount of XRP. There is a traderX who wants to sell 7000 XRP so in this case he may have a deal with trader1 and partial deal with trader2. However, this is not how all exchangers work, right? Usually all orders processed as a single transaction.

So how all these orders match to have a trading? Any algorithm or code in any programming language would be very helpful. Thank you!


"so in this case he may have a deal with trader1 and partial deal with trader2."

This happens all the time in the markets. Majority of the people don't really notice this happen because the size of the trades are small enough relative to the liquidity of the market and get they get complete fills.

If you tried selling a huge amount, lets say, 1000000 XRP at a particular BTC price, you're likely not going to get a complete fill right away.

Another way to get a 100% fill is when some other trader places a market order bigger than the size of your limit order. In that case, the exchange will "eat through" your limit order and move on to the next best available order in the orderbook. Or may be there are multiple market orders that can be filled against your limit order, so your limit order gets filled as more and more market orders come through.

There's a lot to read about similar topics, search for order matching algorithms: https://stackoverflow.com/questions/13112062/which-are-the-order-matching-algorithms-most-commonly-used-by-electronic-financi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.