Author

Topic: Writing an exchange can be hard (Read 932 times)

hero member
Activity: 854
Merit: 500
April 27, 2013, 09:45:53 AM
#6
There are sell orders (1)  for 1 BTC @ 150 USD, and another (2) for 1 BTC @ 160 USD... Now someone wants to buy both of them. So he figures that it's a good idea to put in a buy order (3) for 2 BTC @ 155 USD. What happens?

The guy cannot buy both for 155.

His order will go through on the 150 USD order and sit there with an buy @155 while the other guy has a sell at @160.

I would be pissed if I put on an exchange that I am willing to sell my bitcoin for $160 and the exchange sold it to some guy for $155.

No the seller @ $150 gets $150.
The seller @ $160 gets $160.

This sounds like it is a good algorithm that no exchange right now already has. Most exchanges right now will buy @ $150 and give you $5 back so you have $160 laying in your account, but the exchange does not have your permission to buy @ $160.

Unless you do a market order for all your money.
legendary
Activity: 3598
Merit: 2386
Viva Ut Vivas
April 26, 2013, 08:29:16 PM
#5
There are sell orders (1)  for 1 BTC @ 150 USD, and another (2) for 1 BTC @ 160 USD... Now someone wants to buy both of them. So he figures that it's a good idea to put in a buy order (3) for 2 BTC @ 155 USD. What happens?

The guy cannot buy both for 155.

His order will go through on the 150 USD order and sit there with an buy @155 while the other guy has a sell at @160.

I would be pissed if I put on an exchange that I am willing to sell my bitcoin for $160 and the exchange sold it to some guy for $155.
member
Activity: 89
Merit: 10
April 26, 2013, 06:33:31 AM
#4
One of the key things about an exchange is that they should be completely transparent in how this is done.  One of the core things missing from the bitcoin market place is a regulator to enforce these kinds of rules.

I have noticed the same - no clear explanation on how the orders actually work. Perhaps that would be one competitive advantage over the existing players.

With crypto, our matching systems work on price efficiency. You place a buy order for 20 BTC at $148 per. There is a sell order up for 92 BTC at $145 per. Let us pretend that there are many other sell orders in the system, but all higher. This is the only buy order in the universe however.

You're matched with the $145 per and get your $3 per coin back. The 0.18% trading fee is then calculated afterwards in order to ensure the cheapest possible deal for you.

We're working on complete transparency and are currently looking for a reliable firm to do regular public audits of our platform and finances. I agree with you, this all needs to be transparent!
member
Activity: 66
Merit: 10
April 26, 2013, 06:23:52 AM
#3
One of the key things about an exchange is that they should be completely transparent in how this is done.  One of the core things missing from the bitcoin market place is a regulator to enforce these kinds of rules.

I have noticed the same - no clear explanation on how the orders actually work. Perhaps that would be one competitive advantage over the existing players.
member
Activity: 73
Merit: 10
www.bitex.co.uk - A new begining in cryptotech
April 26, 2013, 06:02:49 AM
#2
An Exchange should never execute orders in a way that then makes them anything over and above their transaction fee's.

There are several Matching algorithms that exchanges usually use this site goes into them:

https://sites.google.com/site/rajeevranjansingh/order-matching-execution-side

One of the key things about an exchange is that they should be completely transparent in how this is done.  One of the core things missing from the bitcoin market place is a regulator to enforce these kinds of rules.

member
Activity: 66
Merit: 10
April 26, 2013, 05:52:56 AM
#1
Consider this case (ignoring transaction fees for a second):

There are sell orders (1)  for 1 BTC @ 150 USD, and another (2) for 1 BTC @ 160 USD... Now someone wants to buy both of them. So he figures that it's a good idea to put in a buy order (3) for 2 BTC @ 155 USD. What happens?

If the exchange wants to be nasty, it can combine orders (1) and (3), buy the bitcoin from the seller at 150 USD and sell it to buyer at 155 USD. Exchange makes a profit of 5 USD and both the seller and the buyer got what they wanted (sort of). The leftover of the buy order (1 BTC @ 155 USD) is left on the order book.

If the exchange wants to be nice, it can combine orders (1) and (3), but this time decide that whoever comes later gets the better price. So the buyer gets 1 BTC at 150 USD, and the order of 1 BTC @ 155 USD is again left on the order book. This has the additional problem that the prices are indeterministic: if (1) is placed slightly after (3), the trade takes place at 155 USD - if not, it takes place at 150 USD.

So another solution is to execute the two best orders at the price halfway between bid and ask price. So the trade would take place at 152.5 USD.  

But none of the solutions gets the buyer what he originally wanted, i.e. 2 BTC at the average price of 155 USD.

So the "perfect" solution is to write a filling algorithm that goes through the sell orders starting from the most affordable, consuming bitcoins until the average price becomes 155 USD. (Yeah, he might've just put in a market order for 2 BTC, but what if he wanted to be *sure* that he'd get them at @155 or better?)

Or is it? Do you people actually care about this stuff?

(Because, damn it, implementing these kind of "perfect" things can get complex really quickly. Especially when you consider all of the different cases: usually the volumes between paired orders do not balance up, so you have to split orders into two; now there's three different ways how buy/sell orders are executed partially, then there's fees and balance reservations to consider, and then there are rounding errors... after a while you start to realize that it's actually quite a bit of work to make an actually working exchange. I wonder what all of those exchanges did that went belly up...)
Jump to: