stockmarket
Class MarketMaker

java.lang.Object
  |
  +--support.Ticker.RefMarketMaker
        |
        +--stockmarket.MarketMaker

public class MarketMaker
extends RefMarketMaker

This class implements the actions of a market maker who handles all the trades for a certain stock.

Buy orders and sell orders sent to the market maker specify the number of share (size) and the price. The market maker assigns a unique ID to each order, which can be later used to cancel the order.

The market maker maintains a priority queue of open buy orders and a priority queue of open sell orders, such that the best bid (highest price of a buy-order) is strictly less than the best ask (lowest price of a sell-order).

Whenever a new order arrives, the market maker tries to match it with open orders of the opposite type. A maximal series of trades are then executed crossing matching orders. Spreads between the prices of matching orders give a profit to the market maker.

The market disseminates the transactions performed by means of the following events:

Each event has an ID, size, and price. Spread events have ID=0.


Fields inherited from class support.Ticker.RefMarketMaker
BuyOrders, IDTable, SellOrders
 
Constructor Summary
MarketMaker()
           
 
Method Summary
 java.util.Enumeration buyOrder(int size, int price)
          process a buy order
protected  void crossOrders(Sequence events)
          execute a maximal series of trades by matching open buy and sell orders, and profit from spreads
protected  int id(Locator loc)
          adaptor
 java.util.Enumeration openOrders()
          list open orders
protected  int price(Locator loc)
          adaptor
protected  void setID(Locator loc, int id)
          adaptor
protected  void setSize(Locator loc, int size)
          adaptor
protected  int size(Locator loc)
          adaptor
 
Methods inherited from class support.Ticker.RefMarketMaker
cancel, sellOrder
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

MarketMaker

public MarketMaker()
Method Detail

buyOrder

public java.util.Enumeration buyOrder(int size,
                                      int price)
process a buy order
Returns:
events triggered by the order
Overrides:
buyOrder in class RefMarketMaker

openOrders

public java.util.Enumeration openOrders()
list open orders
Returns:
events associated with open orders
Overrides:
openOrders in class RefMarketMaker

crossOrders

protected void crossOrders(Sequence events)
execute a maximal series of trades by matching open buy and sell orders, and profit from spreads
Overrides:
crossOrders in class RefMarketMaker

price

protected int price(Locator loc)
adaptor
Overrides:
price in class RefMarketMaker

size

protected int size(Locator loc)
adaptor
Overrides:
size in class RefMarketMaker

setSize

protected void setSize(Locator loc,
                       int size)
adaptor
Overrides:
setSize in class RefMarketMaker

id

protected int id(Locator loc)
adaptor
Overrides:
id in class RefMarketMaker

setID

protected void setID(Locator loc,
                     int id)
adaptor
Overrides:
setID in class RefMarketMaker