ftex.broker
Class BrokerBean

java.lang.Object
  extended byftex.broker.BrokerBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, java.io.Serializable, javax.ejb.SessionBean

public class BrokerBean
extends java.lang.Object
implements javax.ejb.SessionBean

Provides methods to perform operations needed by clients to access the market.

See Also:
Serialized Form

Constructor Summary
BrokerBean()
           
 
Method Summary
 boolean checkUserName(java.lang.String u_name)
          Check if username already exist within account database
 boolean createAccount(java.lang.String u_name, java.lang.String u_passwd, java.lang.String u_first, java.lang.String u_last, java.lang.String transactionID)
          Create new account.
 void ejbActivate()
           
 void ejbCreate()
           
 void ejbPassivate()
           
 void ejbRemove()
           
 Account getAccount(java.lang.String username)
          Returns Account object for username
 double getBuyOrderPrice(java.lang.String symbol)
          Returns the highest buying price for a stock in its order book
 java.util.Collection getBuyOrders(java.lang.String symbol, int maxDisplay)
          Returns a collection of Buy orders sorted descending by price(Highest to lowestprice)
 java.lang.String getBuyOrderStr(java.lang.String symbol, int maxDisplay)
          Returns a string with a specified number of details of buy orders the orders a sorted from high to low price
 double getLastTransactionPrice(java.lang.String symbol)
          Returns the last price a stock as transacted at.
 java.lang.String getMarketStr()
          Return with a string with the symbol,last price,bid and ask prices for all symbols in market
 java.util.Collection getOutstanding(java.lang.String clientID)
          Lists all orders that are outstanding for a certain user.
 double getSellOrderPrice(java.lang.String symbol)
          Returns the price of the lowest selling price for a stock in its order book
 java.util.Collection getSellOrders(java.lang.String symbol, int maxDisplay)
          Returns a collection of Sell orders sorted accending by price(Lowest to highest price)
 java.lang.String getSellOrderStr(java.lang.String symbol, int maxDisplay)
          Returns a string with a specified number of details of sell orders the orders a sorted from low to high price
 java.util.Collection getTransactions(java.lang.String clientID)
          Lists all past transactions for a certain user.
 java.util.Collection getUniqueSymbols()
          Returns a collection of Strings of unique stock symbols from order book
 boolean isAlive()
          Used to pooling to see if the server is alive
 boolean login(java.lang.String userName, java.lang.String password)
          Determines if username and password matches with client database
 boolean modifyAccount(java.lang.String u_name, java.lang.String password, java.lang.String f_name, java.lang.String l_name, java.lang.String transactionID)
          modifies account.
 int putOrder(java.lang.String symbol, java.lang.String orderType, java.lang.String orderMethod, java.lang.Integer quantity, java.lang.Double price, java.lang.String clientID, java.lang.String transactionID)
          Puts an order of a given stock symbol into order book.
 void setSessionContext(javax.ejb.SessionContext ctx)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BrokerBean

public BrokerBean()
Method Detail

putOrder

public int putOrder(java.lang.String symbol,
                    java.lang.String orderType,
                    java.lang.String orderMethod,
                    java.lang.Integer quantity,
                    java.lang.Double price,
                    java.lang.String clientID,
                    java.lang.String transactionID)
Puts an order of a given stock symbol into order book. If it is a market order, it will execute the order fulfilling as many of the quantity of stock to be bought/sold as possible. If it is a limit order, it will check if there is an opposite order in the order book that can match transactions, if so execute orders for as many quantities as can be fullfilled. Else it will put the order into the order book.

Parameters:
symbol - The stock symbol for the order e.g. MSFT,GOOG
orderType - Type of order, BUY or SELL
orderMethod - Order Method, MARKET or LIMIT order
quantity - Number of stocks to buy or sell
price - Price to sell/buy stocks at. Only valid for LIMIT orders. Ignored for MARKET orders
clientID - userName of client performing transaction
Returns:
1 if order completed. 0 if error occured.

getBuyOrders

public java.util.Collection getBuyOrders(java.lang.String symbol,
                                         int maxDisplay)
Returns a collection of Buy orders sorted descending by price(Highest to lowestprice)

Parameters:
symbol - Stock symbol to get Buy Orders
maxDisplay - Maximum number of orders to return
Returns:
Collection of Orders

getSellOrderPrice

public double getSellOrderPrice(java.lang.String symbol)
Returns the price of the lowest selling price for a stock in its order book

Parameters:
symbol - stock symbol
Returns:
The lowest selling price, -1 if no orders found

getBuyOrderPrice

public double getBuyOrderPrice(java.lang.String symbol)
Returns the highest buying price for a stock in its order book

Parameters:
symbol - stock
Returns:
The highest buying price, -1 if no orders found

getLastTransactionPrice

public double getLastTransactionPrice(java.lang.String symbol)
Returns the last price a stock as transacted at.

Parameters:
symbol - stock symbol to get last transaction price
Returns:
price at which last transaction took place

getUniqueSymbols

public java.util.Collection getUniqueSymbols()
Returns a collection of Strings of unique stock symbols from order book

Returns:
a colletion of Strings with unique stock symbols

getSellOrders

public java.util.Collection getSellOrders(java.lang.String symbol,
                                          int maxDisplay)
Returns a collection of Sell orders sorted accending by price(Lowest to highest price)

Parameters:
symbol - Stock symbol to get Sell Orders
maxDisplay - Maximum number of orders to return
Returns:
Collection of sell orders

getSellOrderStr

public java.lang.String getSellOrderStr(java.lang.String symbol,
                                        int maxDisplay)
Returns a string with a specified number of details of sell orders the orders a sorted from low to high price

Parameters:
symbol - stock symbol
maxDisplay - number of orders
Returns:
sell order price and quantity separated by "\t\t" and new line between orders

getBuyOrderStr

public java.lang.String getBuyOrderStr(java.lang.String symbol,
                                       int maxDisplay)
Returns a string with a specified number of details of buy orders the orders a sorted from high to low price

Parameters:
symbol - stock symbol
maxDisplay - number of orders
Returns:
buy order price and quantity separated by "\t\t" and new line between orders

getMarketStr

public java.lang.String getMarketStr()
Return with a string with the symbol,last price,bid and ask prices for all symbols in market

Returns:
"symbol\t\t last price \t\t bid \t\t ask prices \n

getOutstanding

public java.util.Collection getOutstanding(java.lang.String clientID)
Lists all orders that are outstanding for a certain user. These are orders that have not been transacted yet and are in order books

Parameters:
clientID - user name or client name
Returns:
Collection of outstanding offers. Maybe an empty Collection.

getTransactions

public java.util.Collection getTransactions(java.lang.String clientID)
Lists all past transactions for a certain user.

Parameters:
clientID - user name or client name
Returns:
Collection of past transactions. Maybe an empty Collection.

login

public boolean login(java.lang.String userName,
                     java.lang.String password)
Determines if username and password matches with client database

Parameters:
userName - client user name
password - user login password
Returns:
TRUE if username and password match, FALSE otherwise

createAccount

public boolean createAccount(java.lang.String u_name,
                             java.lang.String u_passwd,
                             java.lang.String u_first,
                             java.lang.String u_last,
                             java.lang.String transactionID)
Create new account. Does not check username already exist.

Parameters:
u_name - username
u_passwd - password
u_first - User First Name
u_last - User Last Name
Returns:
True if account create,false otherwise

checkUserName

public boolean checkUserName(java.lang.String u_name)
Check if username already exist within account database

Parameters:
u_name - to check
Returns:
TRUE if username is in use, false otherwise

getAccount

public Account getAccount(java.lang.String username)
Returns Account object for username

Parameters:
username - username of account to find
Returns:
Account that was found. Maybe null if account not found.

modifyAccount

public boolean modifyAccount(java.lang.String u_name,
                             java.lang.String password,
                             java.lang.String f_name,
                             java.lang.String l_name,
                             java.lang.String transactionID)
modifies account. Assumes account exist or not exception will be thrown.

Parameters:
u_name - username of account to edit
password - new password to change to. if null, password unchanged
f_name - first name to change to. if null, first name unchanged
l_name - last name to change to. if null, last name unchanged
Returns:
true if user account successfully changed. else false.

isAlive

public boolean isAlive()
Used to pooling to see if the server is alive

Returns:
Returns true all the time

ejbActivate

public void ejbActivate()
                 throws javax.ejb.EJBException,
                        java.rmi.RemoteException
Specified by:
ejbActivate in interface javax.ejb.SessionBean
Throws:
javax.ejb.EJBException
java.rmi.RemoteException

ejbPassivate

public void ejbPassivate()
                  throws javax.ejb.EJBException,
                         java.rmi.RemoteException
Specified by:
ejbPassivate in interface javax.ejb.SessionBean
Throws:
javax.ejb.EJBException
java.rmi.RemoteException

ejbRemove

public void ejbRemove()
               throws javax.ejb.EJBException,
                      java.rmi.RemoteException
Specified by:
ejbRemove in interface javax.ejb.SessionBean
Throws:
javax.ejb.EJBException
java.rmi.RemoteException

setSessionContext

public void setSessionContext(javax.ejb.SessionContext ctx)
                       throws javax.ejb.EJBException,
                              java.rmi.RemoteException
Specified by:
setSessionContext in interface javax.ejb.SessionBean
Throws:
javax.ejb.EJBException
java.rmi.RemoteException

ejbCreate

public void ejbCreate()
               throws javax.ejb.CreateException
Throws:
javax.ejb.CreateException