Bitcoin Forum
November 07, 2024, 03:35:49 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Writing an exchange can be hard  (Read 932 times)
aes1 (OP)
Member
**
Offline Offline

Activity: 66
Merit: 10



View Profile
April 26, 2013, 10: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...)
Aldur1
Member
**
Offline Offline

Activity: 73
Merit: 10


www.bitex.co.uk - A new begining in cryptotech


View Profile WWW
April 26, 2013, 11: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.


Donations: 1PX1uRHtWzYLBdbbRm2nbhqS3H4QcxqDkD
Bitcoin OTC WoT: http://bitcoin-otc.com/viewratingdetail.php?nick=aldur1
https://www.facebook.com/BitEx.Cryptocurrency.Solutions
https://twitter.com/bitEX_Ltd
http://instagram.com/bitex_ltd
http://www.linkedin.com/company/bitex-ltd
<html>
<a href="http://bitcoin.stackexchange.com/users/13963/hafnero">
<img src="http://bitcoin.stackexchange.com/users/flair/13963.png" width="208" height="58" alt="profile for hafnero at Bitcoin Stack Exchange, Q&amp;A for Bitcoin crypto-currency enthusiasts" title="profile for hafnero at Bitcoin Stack Exchange, Q&amp;A for Bitcoin crypto-currency enthusiasts">
</a>
</html>
aes1 (OP)
Member
**
Offline Offline

Activity: 66
Merit: 10



View Profile
April 26, 2013, 11: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.
Lemon
Member
**
Offline Offline

Activity: 89
Merit: 10


View Profile WWW
April 26, 2013, 11: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!

https://crypto.pm/ -- public cryptocurrency exchange currently in testing.

https://escrow.pm/ -- fee free automated escrow.
Elwar
Legendary
*
Offline Offline

Activity: 3598
Merit: 2386


Viva Ut Vivas


View Profile WWW
April 27, 2013, 01:29:16 AM
 #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.

First seastead company actually selling sea homes: Ocean Builders https://ocean.builders  Of course we accept bitcoin.
infested999
Hero Member
*****
Offline Offline

Activity: 854
Merit: 500



View Profile
April 27, 2013, 02:45:53 PM
 #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.

              ▄███▄   ▄███▄
              █████   █████
      ▄███▄    ▀▀▀     ▀▀▀    ▄███▄
      █████     ▄██▄ ▄██▄     █████
       ▀▀▀ ▄██▄ ▀██▀ ▀██▀ ▄██▄ ▀▀▀
 ▄███▄     ▀██▀           ▀██▀     ▄███▄
 █████ ▄██▄                   ▄██▄ █████
  ▀▀▀  ▀██▀                   ▀██▀  ▀▀▀
                       ▄█
▄███▄ ▄██▄            ███ ███  ▄██▄ ▄███▄
█████ ▀██▀  ████      █████    ▀██▀ █████
 ▀▀▀         ▀███▄    ████           ▀▀▀
       ▄██▄    ████   ███     ▄██▄
 ▄███▄ ▀██▀     ▀███  ███     ▀██▀ ▄███▄
 █████            ███▄██           █████
  ▀▀▀              ▀████            ▀▀▀
                     ███
                     ███
                     ██
                   ███

████    ██
  ████    ██
    ████    ██
      ████    ██
        ████    ██
          ████    ██
          ████    ██
        ████    ██
      ████    ██
    ████    ██
  ████    ██
████    ██










White Paper
Yellow Paper
Pitch Deck
Telegram
LinkedIn
Twitter
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!