Electronic stock trading order book architecture w/coherence?
I would like to maintain a stock and option order book in coherence. This is probably a pretty standard implementation I’m looking at. If anyone has suggestions on some best ways to do this I would appreciate hearing them.
The order objects will manipulated primarily by java applications but being able to operate on them with .NET and C++ apps would be nice also. Multiple trading applications running throughout the enterprise will generate new orders and store them in coherence. The trading applications will choose which of several exchanges the orders should go to. Once the objects are added to Coherence these unsent orders will then need to be sent to the appropriate destination exchange. Several applications, each interfacing with a single exchange, will need to read their orders from coherence, parse them using exchange specific message protocols and fire those messages off to the exchange. This will typically be FIX protocol but not always. Somehow these message processors need to know which unsent cached order objects to get from the cache. What’s the best way for the message processors to be notified that those orders are waiting for them to process? In the event that the message processor or its exchange link is down I would like the trading application which submitted the order to immediately be notified that the order cannot go to that exchange. Orders should not queue up waiting for the link to come back up, but when the link is up orders should queue up in cases where the trading application is able to generate orders more quickly than the exchange link can deliver them. If the exchange links goes down while those pending orders are still enqueued the generating application should be notified and the orders flagged as no longer working.
After orders are sent to the exchange, the exchange will send back messages relating to the status of the order. The trading application which generated the order will need to be advised of those changes. Other applications may want to register an interest in those changes also.
Trading applications will need to make changes to existing orders (probably using an EntryProcessor/ ReflectionUpdater). The message processor applications will need to be advised of those changes so they can pass along a message to the exchange requesting the change. Then the original requesting application will need to be advised that the change was applied. What’s the best way to do that?
For redundancy and increased message throughput there may be multiple message encoders sending messages to the same exchange over different WAN links. In this case I imagine I would need a single queue for that exchange with multiple messaging applications dequing from it simultaneously. Once an initial new order message goes out over a particular link, modifications to it may only be sent over that link which originally submitted it. What’s the best way to accomplish that? Should I populate a HashMap of Order ID to ExchangeLinks as orders are sent and then lookup the original ExchangeLink when a request to modify that order comes through? Since I want each WAN link in its own JVM I would need an application which looks at pending modification requests, does the hashmap lookup and somehow routes the modification request to the original exchange connection – doesn’t seem like the most elegant solution.
Once orders are completely filled or cancelled it’s unlikely they will be modified again. Should I maintain two data structures in coherence, one for working orders which will need to be accessed quickly and one for filled/cancelled orders which may be subject to eviction?
I will configure just one machine as a coherence cache server initially but in the future I’d like multiple machines collocated in financial exchange datacenters and connected by WAN links.
Am I smart to try doing all this w/coherence or would a combination of coherence and some other messaging bus like AMQP be better?
I’ve looking at the Messaging Pattern from the incubator. Should I also be looking at the Push Replication Pattern for some of this?
Thanks!