|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectStock
public class Stock
Represents a stock in the SafeTrade project
Field Summary | |
---|---|
static java.text.DecimalFormat |
money
|
Constructor Summary | |
---|---|
Stock(java.lang.String symbol,
java.lang.String name,
double price)
Constructs a new stock with a given symbol, company name, and starting price. |
Method Summary | |
---|---|
protected void |
executeOrders()
Executes as many pending orders as possible. |
java.lang.String |
getQuote()
Returns a quote string for this stock. |
void |
placeOrder(TradeOrder order)
Places a trading order for this stock. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.text.DecimalFormat money
Constructor Detail |
---|
public Stock(java.lang.String symbol, java.lang.String name, double price)
PriorityQueue
with a PriceComparator
configured for comparing orders in ascending order;
initializes a priority qieue for buy orders
to an empty PriorityQueue
with a PriceComparator
configured for comparing orders in descending order.
symbol
- the stock symbol.name
- full company name.price
- opening price for this stock.Method Detail |
---|
public java.lang.String getQuote()
Giggle.com (GGGL) Price: 10.00 hi: 10.00 lo: 10.00 vol: 0 Ask: 12.75 size: 300 Bid: 12.00 size: 500Or:Giggle.com (GGGL) Price: 12.00 hi: 14.50 lo: 9.00 vol: 500 Ask: none Bid: 12.50 size: 200
public void placeOrder(TradeOrder order)
New order: Buy GGGL (Giggle.com) 200 shares at $38.00Or:
New order: Sell GGGL (Giggle.com) 150 shares at marketExecutes pending orders by calling
executeOrders
.
order
- a trading order to be placed.protected void executeOrders()
You bought: 150 GGGL at 38.00 amt 5700.006. Repeats steps 1-5 for as long as possible, that is as long as there is any movement in the buy / sell order queues. (The process gets stuck when the top buy order and sell order are both limit orders and the ask price is higher than the bid price.)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |