...
Order 14: We are offering 10 GBP for 1 BC
...
Order 18: They are offering 2.5 BC for 5 GBP
...
We need to calculate how much of our order will be chipped off, while
preserving their exchange rate.
...
Order 14-1: We are offering 5 GBP for 2.5 BC
Order 14-2: We are offering 5 GBP for 2.5 BC
...
We fulfill our order and close their order.
...
Order 14-2: We are offering 5 GBP for 2.5 BC
...
A new transaction is created for record keeping purposes and the users funds are
updated accordingly.
I'm not sure this is a good way of doing it.
Suppose I'm trying to buy 1,000 BTC at 10 GBP each. The sellers are wanting 12 GBP each at the moment, so no trade happens. I'm waiting for a seller to ask for less. Then some joker comes along and offers to sell 1 BTC for 1 GBP. His offer matches my request to buy, and so, working the example as before:
...
Order 14: We are offering 10,000 GBP for 1,000 BC
...
Order 18: They are offering 1 BC for 1 GBP
...
We need to calculate how much of our order will be chipped off, while
preserving their exchange rate.
...
Order 14-1: We are offering 1 GBP for 1 BC
Order 14-2: We are offering 9,999 GBP for 9,999 BC
...
We fulfill our order and close their order.
...
Order 14-2: We are offering 9,999 GBP for 9,999 BC
...
A new transaction is created for record keeping purposes and the users funds are
updated accordingly.
After buying the joker's 1 BTC for 1 GBP, the rest of out order is now changed, offering only 1 GBP per BTC. Unless someone else comes along with a very cheap sale, our buy order will never get matched. Even if some 2nd guy comes and offers 1 BTC for 2 GBP, we won't get to buy it, because we're now only offering 1 GBP per BTC. What's the reasoning for changing the rate in "Order 14-2" above? I think it should either keep the GBP spend and rate the same, and buy more BTC with the saving we made from the joker, so if the 2nd part is matched at the rate we requested we end up getting a total of 1,000.9 BTC for 10,000 GBP:
...
Order 14-1: We are offering 1 GBP for 1 BC
Order 14-2: We are offering 9,999 GBP for 999.9 BC
...
or keep the rate and BTC requested the same, and spend less GBP, so if the 2nd part is matched at the requested rate we end up getting 1,000 BTC for a total of 9991 GBP:
...
Order 14-1: We are offering 1 GBP for 1 BC
Order 14-2: We are offering 9,990 GBP for 999 BC
...
Did I misunderstand something? Was the example I quoted wrong? Or is the current implementation kind of weird? Notice this is what happened to Caesium. He offered to sell BTC at a low price when someone was already trying to buy at a higher price and the trade was carried out at his low price.
This is wrong since it uses the initial_amount and initial_want_amount to calculate the exchange rate you set. The amount left that you want is more for display purposes and isn't used internally.