Woo! After some rather fiddly code, I now have an order book working.
Most of the problems seemed to come about from having to handle (near-)empty bid/offer lists at the start of the day's trading - if your first orders are a market-buy and a market-sell, at what price do you match them?
So, anyway, I've got an order book class for a single stock, which supports market/limit/stop/stop-limit order types and (I hope) correctly handles priority with unblocking stop orders.
For time, I've decided to use a (lock-protected) serial number: every order that comes in locks/increments/unlocks the timer, forcing serialisation of requests. None of this two-orders-the-same-age business!
Obviously generalising this to a full exchange is as simple as creating a collection of order books - load balancing isn't an issue when cheating at toy problems ;-)
So, about the biggest thing I'm missing now is the session - the network layer is there, as is the FIX engine, and now the server-side (and even some basic client-side) of the trades. Time to glue it all together!
I figure there's now about a month's work on my "TO DO" list just to get this stuff up to a decent standard, but my goal for the weekend was to have a couple of clients making random trades on a toy exchange, which is certainly looking plausible.
Exchanging Places
Posted by Russ Williams on Saturday, 7th February 2009 at 22:10 GMT
No comments yet | Reply
No comments yet | Reply
