I think the order matching rules are pretty good right now. It seems to be standard (same as other exchanges).
Yes I think this is true.
The margin trading using the current orderbook to determine whether or not to execute sounds like the right way to go. My question is how does it bootstrap?
If I lend funds to someone when there is no order book, then it is impossible to "call".
When you start out with an empty orderbook, no margin trading is allowed. In order to place a margin order in the first place, the system checks to see that the orderbook could handle the new state (where you have a margin position), and checks that you have at least 40% collateral in that new state. (Thats the amount for polo, 40% to start a position or add to it). Then, if things go against you, you are allowed to go down to 20% margin before a margin call happens. While in the 20-40% range, the interface gives you a warning that you are near a margin call and it does not allow you to add to your position, only to reduce it.
I am not sure exactly how the polo system works, but there might be an additional requirement:
If an order on the books would be cancelled, and this cancellation would leave the orderbook with not enough supply remaining, then instead of allowing the order to be cancelled, it instead executes the margin call FIRST, to ensure that the person can pay back what they owe, and then it cancels the rest of the order if needed.
This is needed because otherwise I could set up the following scenario:
I have an order in to buy a large amount of asset at price 100. My order is most of the orderbook.
People then took margin positions which were within collateral requirements, based on my order being in the order book. That is, as long as they can sell into my order, they have sufficient collateral and will be able to pay back the loan.
But then I remove my big order! There is very little remaining orders on the books, and everyone gets margin called and the system tries to sell into what is left, but they cannot get enough funds from it to pay back the people they owe. This would be a failure of the system to protect lenders, it would leave the person who got margin called owing a bunch more BTS that they cannot pay, to other people.
Instead, at the point where I try to remove my big order, the system checks that this removal will cause a margin cascade, and instead of pulling the order, it executes the margin cascade into the order. Then, if some of the order is left unfilled, it is allowed to be pulled.
If you use polo you will know that at times when trading gets crazy and a margin call happens, the system freezes up for a couple seconds. This occurs because the system is forces to do a bunch of calculations and then execute automatic margin call trades, and then recompute again, and do more margin call trades, etc. Only once this process is completed are people allowed to trade normally again.
This might be an issue with the blockchain times, witnesses computers needing to process all these calculations in time, etc. I would imagine that this is a hard technical problem to do on a blockchain. (It was probably hard enough already for polo to implement flawlessly...and it must be flawless). So maybe because of this difficulty we are forced to use a simpler system?