Venice 0.7beta

org.mov.quote
Class IDQuoteCache

java.lang.Object
  extended by org.mov.quote.IDQuoteCache

public class IDQuoteCache
extends java.lang.Object

This class contains all the intra-day stock quotes currently in memory. Its purpose is to cache intra-day stock quotes so that tasks can share copies of the quotes rather than keep duplicate copies.

Tasks should not directly call this class, but should go through a IDQuoteBundle.

When tasks access quotes in a quote cache, either directly or via a quote bundle they can access quotes in two ways. The first way is specifying the actual time they are interested in, i.e. a TradingTime. The other way is specifying a fast access time offset. The fast access time offset is used when lots of quotes have to be queried as fast as possible.

The earliest time in the cache has an offset of 0. The next trading time has an offset of 1, the next 2, etc. This is different from the EODQuoteCache which numbers the latest quote at 0. You can convert to and from fast access times using timeToOffset(org.mov.util.TradingTime) and offsetToTime(int).

Author:
Andrew Leppard
See Also:
IDQuote, IDQuoteBundle

Method Summary
 void addQuoteListener(QuoteListener quoteListener)
          Add a listener to listen for new intra-day quotes.
 int getFirstTimeOffset()
          Return the fast access time offset of the oldest time in the cache.
static IDQuoteCache getInstance()
          Create or return the singleton instance of the quote cache.
 int getLastTimeOffset()
          Return the fast access time offset of the newest time in the cache.
 IDQuote getQuote(Symbol symbol, int timeOffset)
          Get a quote from the cache.
 double getQuote(Symbol symbol, int quoteType, int timeOffset)
          Get a quote from the cache.
 void load(java.util.List quotes)
          Load a time slice of intra-day quotes into the cache.
 TradingTime offsetToTime(int timeOffset)
          Convert between a fast access time offset and a time.
 void removeQuoteListener(QuoteListener quoteListener)
          Remove a listener for new intra-day quotes.
 int timeToOffset(TradingTime time)
          Convert between a time and its fast access time offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static IDQuoteCache getInstance()
Create or return the singleton instance of the quote cache.

Returns:
singleton instance of this class

getQuote

public double getQuote(Symbol symbol,
                       int quoteType,
                       int timeOffset)
                throws QuoteNotLoadedException
Get a quote from the cache.

Parameters:
symbol - the symbol to load
quoteType - the quote type, one of Quote.DAY_OPEN, Quote.DAY_CLOSE, Quote.DAY_LOW, Quote.DAY_HIGH, Quote.DAY_VOLUME, Quote.BID, Quote.ASK.
timeOffset - fast access time offset
Returns:
the quote
Throws:
QuoteNotLoadedException - if the quote was not in the cache

getQuote

public IDQuote getQuote(Symbol symbol,
                        int timeOffset)
                 throws QuoteNotLoadedException
Get a quote from the cache.

Parameters:
symbol - the symbol to load
timeOffset - fast access time offset
Returns:
the quote
Throws:
QuoteNotLoadedException - if the quote was not in the cache

load

public void load(java.util.List quotes)
Load a time slice of intra-day quotes into the cache. Each of these quotes will be given the same fast time offset and thus considerd as a group in time, even if their given times are slightly different.

Parameters:
quotes - list of quotes to cache

timeToOffset

public int timeToOffset(TradingTime time)
Convert between a time and its fast access time offset. Returns a negative number if the time is not in the cache.

Parameters:
time - the time
Returns:
fast access time offset

offsetToTime

public TradingTime offsetToTime(int timeOffset)
Convert between a fast access time offset and a time. Returns null if the time is not in the cache.

Parameters:
timeOffset - fast access time offset
Returns:
the time

getFirstTimeOffset

public int getFirstTimeOffset()
Return the fast access time offset of the oldest time in the cache.

Returns:
the fast access time offset of the oldest time in cache or -1 if there are no times in the cache.

getLastTimeOffset

public int getLastTimeOffset()
Return the fast access time offset of the newest time in the cache.

Returns:
the fast access time offset of the oldest time in cache or -1 if there are no times in the cache.

addQuoteListener

public void addQuoteListener(QuoteListener quoteListener)
Add a listener to listen for new intra-day quotes.

Parameters:
quoteListener - the class to be informed about new intra-day quotes

removeQuoteListener

public void removeQuoteListener(QuoteListener quoteListener)
Remove a listener for new intra-day quotes.

Parameters:
quoteListener - the object to remove

Venice 0.7beta