Class Quotes

java.lang.Object
  |
  +--Quotes

public class Quotes
extends java.lang.Object

source
class diagram

This class retrieves quote data and configuration parameters from the server using URLFile. It also provides a delimited string tokenizer and functions for manipulating floats and fractions.

The complete configuration list is read from the codebase directory using CONFIG_FILENAME and getConig(...). The configuration file consists of a list of name value pairs. Individual configuration values are accessed using getConfigValue(...).

The "QUOTELOOKUP" configuration parameter is used to process quote requests using getQuotes(...). Quote data returned is accessed using getQuote(...). QuoteInfo is used to maintain parsed quote data.

The "STATUS", "TRANS", and "CLOSING" config parameters are used to retrieve siac_tape data using getStatus(...) and getTransactionTickerData(...).

To tokenize a delimited string, myTokenizer(...) is provided. This simple tokenizer handles empty delimited fields better than StringTokenizer.

To manipulate quote data, addSign(...), fractionToFloat(...), getFractions(...), StringToFloat(...) and formatFloatStr(...) methods are provided.

Version:
1.0 08/14/99
Author:
David Mannies

Inner Class Summary
 class Quotes.QuoteInfo
          
Class used to maintain stock quote data retrieved from quote processor.
 
Field Summary
(package private) static java.net.URL codeBase
          directory for codebase applet
(package private) static java.util.Hashtable config
          configuration name/value pairs
(package private) static java.lang.String CONFIG_FILENAME
          configuration file name in codebase directory
(package private)  java.net.URL documentBase
          document base
(package private)  boolean isClosed
          true if market is closed
(package private)  boolean isError
          true if error status reported
(package private)  boolean isOpen
          true if market is open
(package private)  java.lang.String lastUpdated
          last updated time as reported by quotes processor
(package private) static int MINIMUM_REFRESH_INTERVAL
          minimum refresh interval
(package private)  java.util.Vector quotes
          all quotes returned by quotes processor
(package private)  java.util.Hashtable quotesHashed
          quotes keyed by ticker symbol
(package private)  int refreshInterval
          current refresh interval
(package private)  char status
          status character value; 0 = closed, 1 = open, - = error
(package private) static boolean TRACE
          set to true if tracing information wanted on System.out
 
Constructor Summary
Quotes(java.net.URL documentBase, java.net.URL codeBase)
          Default constructor for Quotes requiring document base and code base directories.
 
Method Summary
(package private) static java.lang.String addSign(java.lang.String v, float v_f)
          Adds sign to given value if missing using given float value.
(package private) static java.lang.String configName(java.lang.String data)
          Returns name of given name value pair.
(package private) static java.lang.String configValue(java.lang.String data)
          Returns value of given name value pair.
(package private) static java.lang.String formatFloatStr(double d, int numDecPlaces)
          Convert given value to String with minimum decimal places.
(package private) static java.lang.String formatFloatStr(float f, int numDecPlaces)
          Convert given value to String with minimum decimal places.
(package private) static java.lang.String formatFloatStr(java.lang.String s, int numDecPlaces)
          Convert given value to String with minimum decimal places.
(package private) static float fractionToFloat(java.lang.String[] value)
          Returns float value of string array of fractional parts.
(package private) static void getConfig(java.lang.String codeBase)
          Reads the configuration file on server.
(package private) static java.lang.String getConfigValue(java.lang.String name)
          Returns requested configuration parameter.
(package private) static java.lang.String[] getFractions(java.lang.String value)
          Returns string arrary of fractional parts parsed from given complete value with: value[0] as complete value; value[1] as whole value; value[2] as numerator; and value[3] as denominator.
 Quotes.QuoteInfo getQuote(java.lang.String ticker)
          Returns QuoteInfo keyed to given ticker name.
 int getQuotes(java.lang.String tickers)
          Retrieves quote data from quotes processor as mutli line response.
 int getStatus()
          Returns delayed status of market.
 java.lang.String getTransactionTickerData(java.lang.String TICKER_INTERVAL, java.lang.String previous)
          Returns transation ticker data as s single continuous string.
(package private) static java.lang.String[] myTokenizer(java.lang.String data, int max)
          Default tokenizer using '|' as default field delimitor.
(package private) static java.lang.String[] myTokenizer(java.lang.String data, int max, char delimiter)
          Returns an array of strings parsed from given data.
(package private) static float stringToFloat(java.lang.String value)
          Returns float value of given string.
(package private) static float StringToFloat(java.lang.String s)
          Returns float value of given string.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

TRACE

static boolean TRACE
set to true if tracing information wanted on System.out

MINIMUM_REFRESH_INTERVAL

static final int MINIMUM_REFRESH_INTERVAL
minimum refresh interval

CONFIG_FILENAME

static final java.lang.String CONFIG_FILENAME
configuration file name in codebase directory

config

static java.util.Hashtable config
configuration name/value pairs

codeBase

static java.net.URL codeBase
directory for codebase applet

refreshInterval

int refreshInterval
current refresh interval

lastUpdated

java.lang.String lastUpdated
last updated time as reported by quotes processor

quotes

java.util.Vector quotes
all quotes returned by quotes processor

quotesHashed

java.util.Hashtable quotesHashed
quotes keyed by ticker symbol

documentBase

java.net.URL documentBase
document base

isOpen

boolean isOpen
true if market is open

isClosed

boolean isClosed
true if market is closed

isError

boolean isError
true if error status reported

status

char status
status character value; 0 = closed, 1 = open, - = error
Constructor Detail

Quotes

public Quotes(java.net.URL documentBase,
              java.net.URL codeBase)
Default constructor for Quotes requiring document base and code base directories. Reads configuration file from server.
Parameters:
documentBase - url for
codeBase - url for
Method Detail

configName

static java.lang.String configName(java.lang.String data)
Returns name of given name value pair.
Parameters:
data - to parse name from
Returns:
name of name value pair

configValue

static java.lang.String configValue(java.lang.String data)
Returns value of given name value pair.
Parameters:
data - to parse value from
Returns:
value of name value pair

getConfig

static void getConfig(java.lang.String codeBase)
Reads the configuration file on server. The configuration consists of a list of name value pairs stored in a hashtable with each nvp value keyed by nvp name.

Current configuration file:

status = ../data/status.dat
closing = ../data/closing.dat
trans = ../data/trans.dat
quoteLookup = http://cgi.nyse.com/cgi-bin/quoteLookup.cgi?tickers=
imagesListed = http://cgi.nyse.com/images/listed/tic-
tickerLoad = http://www2.nyse.com/marketinfo/marketinfo.html?sym=
browserWindowName = "NYSE"

Parameters:
codeBase - to use

getConfigValue

static java.lang.String getConfigValue(java.lang.String name)
Returns requested configuration parameter. If configuration parameter is not found, will reread configution file once.
Parameters:
name - configuration parameter name
Returns:
configuration parameter value

myTokenizer

static java.lang.String[] myTokenizer(java.lang.String data,
                                      int max)
Default tokenizer using '|' as default field delimitor.
Parameters:
data - to parse
max - number of data values expected
Returns:
array of strings of delimited fields

myTokenizer

static java.lang.String[] myTokenizer(java.lang.String data,
                                      int max,
                                      char delimiter)
Returns an array of strings parsed from given data. Length of arrary will be the given maximum field expected setting. Array is padded with empty strings if actual count of parsed strings is less than maximum. Strings exceeding maximum expected are ignored. This tokenizer handles empty delimited fields better than StringTokenizer.
Parameters:
data - to parse
max - number of data values expected
delimiter - for each field
Returns:
array of strings of delimited fields

addSign

static java.lang.String addSign(java.lang.String v,
                                float v_f)
Adds sign to given value if missing using given float value.
Parameters:
v - to add missing sign to if sign not found
v_f - float value of v
Returns:
value with sign

fractionToFloat

static float fractionToFloat(java.lang.String[] value)
Returns float value of string array of fractional parts.
Parameters:
value - fractional parts of value with value[0] as complete value; value[1] as whole value; value[2] as numerator; and value[3] as denominator
Returns:
float value of given fractional parts

getFractions

static java.lang.String[] getFractions(java.lang.String value)
Returns string arrary of fractional parts parsed from given complete value with: value[0] as complete value; value[1] as whole value; value[2] as numerator; and value[3] as denominator. If value does not have fractional parts, empty string returned for numerator and denominator.
Parameters:
value - to parse fractional parts from
Returns:
string array of fractional parts

StringToFloat

static float StringToFloat(java.lang.String s)
Returns float value of given string. Invalid numbers are returned as 0.
Parameters:
s - string to convert to float
Returns:
float value of string

formatFloatStr

static java.lang.String formatFloatStr(java.lang.String s,
                                       int numDecPlaces)
Convert given value to String with minimum decimal places. If value is > 10 million, returns >10 million.
Parameters:
s - value to convert
numDecPlaces - minimum decimal places to pad to if required
Returns:
string value

formatFloatStr

static java.lang.String formatFloatStr(float f,
                                       int numDecPlaces)
Convert given value to String with minimum decimal places. If value is > 10 million, returns >10 million.
Parameters:
f - value to convert
numDecPlaces - minimum decimal places to pad to if required
Returns:
string value

formatFloatStr

static java.lang.String formatFloatStr(double d,
                                       int numDecPlaces)
Convert given value to String with minimum decimal places. If value is > 10 million, returns >10 million.
Parameters:
d - value to config
numDecPlaces - minimum decimal places to pad to if required
Returns:
string value

stringToFloat

static float stringToFloat(java.lang.String value)
Returns float value of given string. Returns 0 for invalid formated numbers.
Parameters:
value - to get float of
Returns:
float value

getQuote

public Quotes.QuoteInfo getQuote(java.lang.String ticker)
Returns QuoteInfo keyed to given ticker name. If ticker name is not found, returns null.
Parameters:
ticker - value to get
Returns:
QuoteInfo for given ticker or null if not found

getQuotes

public int getQuotes(java.lang.String tickers)
Retrieves quote data from quotes processor as mutli line response. Quote processing is invoked using configuration "QUOTELOOKUP". The 1st line is refresh interval; 2nd line last updated time stamp; and following lines being individual quotes for given list of tickers. The state of this object's refresh interval, lasted updated time stamp, and list of quote data is set to the quotes processor's response.
Here is an example request and response.

Request:
http://cgi.nyse.com/cgi-bin/quoteLookup.cgi?tickers=IBM|ASDFF|AOL|DJI|INX|NYA.X|IUX|COMPX

Response:
30
As of 13:56, Aug. 13
IBM|123 15/16|2 13/16|1|As of 13:56, Aug. 13
ASDFF|not found
AOL|96 3/8|3 5/8|1|As of 13:56, Aug. 13
DJI|10973.30|183.90|0|As of 14:16, Aug. 13
INX|1325.54|27.38|0|As of 14:16, Aug. 13
NYA.X|620.83|10.20|0|As of 14:16, Aug. 13
IUX|432.99|4.17|0|As of 14:16, Aug. 13
COMPX|2623.39|73.90|0|As of 14:16, Aug. 13

Parameters:
tickers - stock symbols to get quote data for
Returns:
total number of lines read

getStatus

public int getStatus()
Returns delayed status of market. Sets isOpen, isClosed, isError, and status. Market status is read from the configuration "STATUS" file. A value of '1' is for a opened market, a value of '0' os for a closed market, any other values are read as error. isOpen and isClosed are not updated if market status is read as error, however, status is.
Example files for closed:
0
or for open:
1
or for error:
-1
Returns:
number of lines read from file

getTransactionTickerData

public java.lang.String getTransactionTickerData(java.lang.String TICKER_INTERVAL,
                                                 java.lang.String previous)
Returns transation ticker data as s single continuous string. Data read is dependent on current delayed market status as read by getStatus(). If market is open, the configuration "TRANS" file is read. If closed, the configuration "CLOSING" file is read. The "TRANS" file contains a refresh interval that is returned and a time stamp field that is ignored.
Example trans.dat file:

60
As of 02:46PM, Aug 13
1426|CPU|10s5 3/4
1426|AHC|2s64 1/16
1426|NSS|5s11 3/4
1426|AAN-A|10s24 3/8
1426|AOL|95 3/4
1426|AOL|95 11/16
typically over 500 lines per file

Example closing.dat file:

As of closing, Aug 13
AA|67 3/4
AAC|6 1/4
AAE|24 7/8
AAG|22 15/16
AAG-T|25 3/8
there is an entry for ever NYSE stock, giving more than 3000 lines

Parameters:
TICKER_INTERVAL -  
pervious - data read used to ignore previously read data
Returns:
transaction ticker data