Finance::Streamer(3) Interface to Datek Streamer.

VERSION

This document refers to version 1.07 of Finance::Streamer, released Tue, 27 Aug 2002.

SYNOPSIS


use Finance::Streamer;
my $user = 'USER1234';
my $pass = 'SF983JFDLKJSDFJL8342398KLSJF8329483LF';
my $symbols = 'JDSU+QCOM+AMAT+IBM+^COMPX';
my $fields = '0+1+2+3+4+8+9+21';
my $streamer = Finance::Streamer->new( user => $user,
pass => $pass,
symbols => $symbols,
fields => $fields,
);
my $sub = sub
{
my (%all_data) = @_;
foreach my $symbol (keys %all_data) {
print "$symbol\n";
my %data = %{$all_data{$symbol}};
foreach my $data_part (keys %data) {
print "$data_part", "=", $data{$data_part}, "\n";
}
}
};
$streamer->{sub_recv} = $sub;
#$streamer->receive;
$streamer->receive_all;

DESCRIPTION

This library provides an interface that can be used to access Datek Streamer market data.

It works with the new Streamer (version 3) as opposed to the older (version 2).

There are four subroutines available to use. The first two, connect and Parser, make the required tasks of connecting to a Streamer server and parsing raw quote data into an easier to use format (such as a hash) easy to do. The third, receive, makes the task of using the data as easy as possible by using the previously mentioned subroutines (connect, receive). The fourth, receive_all, is identical to receive but it returns the data state.

If you just want to use the data, focus on the functions receive and receive_all. If you want to know how the protocol works (roughly), focus on the connect and Parser functions.

OPERATIONS

Finance::Streamer->new;

        Returns: defined object on success, FALSE otherwise

The new sub stores the values passed to it for use by other subroutines later. For example, if you wanted to use a subroutine that required a value for symbols to be defined, you could do it like so.

 $obj = Finance::Streamer->new(symbols => $your_symbols)
        or die "error new()";
 # then use the sub that requires "symbols"

$obj->connect;

        Returns: IO::Socket::INET object on success, FALSE on error
        Requires the following object attributes:
                user pass symbols fields [agent] [timeout]

The connect sub is used to initiate a connection with the data server.

The object attributes user, pass, symbols, fields, optional agent, and an optional timeout, must be defined in the streamer object before using this subroutine. Each is describe in more detail below.

 $obj->{user} = $user;
 $obj->{pass} = $pass;
 $obj->{symbols} = $symbols;
 $obj->{fields} = $fields;
 $obj->{agent} => $agent;       # optional
 $obj->{timeout} => $timeout;   # optional

The user and pass value is the user name and password of the account to be used for receiving data. See the section ``how to obtain user name and password'' below, for more info.

IMPORTANT - If the user or pass is wrong, there is no indication other than no data arriving after connection.

The symbols value can contain up to 23 symbols in all uppercase joined by a '+' character.

 $symbols = "JDSU+QCOM+AMAT+IBM";

The fields value can be any combination of the integers 0 to 21 in sequential order joined by the '+' character. See the section ``field numbers'' below, for more info.

 $fields = "0+1+2+3+21";

The agent field determines the id of this library when it connects to a Streamer server. By default the id is the name of this library. The string should be one line with no carriage return ('\n').

 $agent = "My Server 1.01";

The timeout specifies the maximum number of seconds to wait for the connection to succeed. The default value of 60 seconds is used if no value is specified.

 $timeout = 30;
 my $sock = $obj->connect
        or die "error connect()";

Finance::Streamer::Parser($raw_data);

        Returns: %data on success, FALSE otherwise

The Parser subroutine changes raw quote data into a form that is easier to use.

IMPORTANT - The raw quote data must have been received using the fields value 0 or this subroutine wont work.

This subroutine does not use the streamer object, so the name must be fully specified. The only argument that is required is a variable containing the raw data for a quote.

If the parser is successful a hash containing the data will be returned. The hash will contain a key for each symbol that data was received for. Each symbol entry is a reference to another hash that has a key for each value that data is available for. A helpful tool for visualizing this is the Data::Dumper module.

Many checks/tests are made while the data is being parsed. If something is wrong with the data, an error message will be printed to STDERR and undef will be returned if the error was substantial enough that the quote data is wrong.

$obj->receive;

        Returns: does not return
        Requires the following object attributes:
                sub_recv user pass symbols fields [timeout] [sub_hrtbt]

The receive subroutine deals with all the issues of connecting to the server, receiving data, etc, and executes the subroutine specified by sub_recv, passing a single argument which contains the quote data every time a quote is received.

The object attributes sub_recv, user, pass, symbols, fields, optional timeout and optional sub_hrtbt must be defined before using this subroutine.

 $obj->{sub_recv} = $sub_ref;
 $obj->{sub_hrtbt} = $sub_ref_heartbeat;

The sub_recv value is a reference to a subroutine to be executed when new quote data arrives. One argument, an object of parsed data as returned by Parser, will be passed to this subroutine.

The values user, pass, symbols, fields and timeout are used for the connect subroutine. See the section on connect for more information.

The timeout value, while it is used for connect, is also used in this subroutine to specify the maximum number of seconds to wait for new data to arrive before reconnecting. The default value of 60 seconds is used if no value is specified.

The sub_hrtbt value is a reference to a subroutine to be executed when a heartbeat happens. One argument, the time at which the heartbeat occurred, will be passed to this subroutine when executed.

Error messages may be displayed. Messages about errors receiving data will indicate why and may result in a reconnection. Messages about the status indicated in the received data are for information purposes and do not usually result in a reconnect. All messages are displayed to STDERR and so can be easily redirected. An example of how to turn off messages is below, where ``a.out'' is the name of the program and ``2'' is the number of the file descriptor representing standard error.

 a.out 2>/dev/null

$obj->receive_all;

Identical to the function receive() except that instead of getting just the changed values, any values that do not have changed values have their most recent value. So, it sort of keeps a current state changing only the values that are updated returning the current state.

 Example:
 1: bid_size = 200, ask_size = 300
 2: bid_size = 400                      # receive()
 2: bind_size = 400, ask_size = 300     # receive_all()

NEED TO KNOW

This section contains information that must be understood in order to use this library.

how to obtain user name and password

When you first start the Streamer application provided by Datek a window will pop up giving you a choice of what you want to launch (Streamer, Portfolio, Last Sale, Index). If you look at the html source of that window you will find near the top a place where your user name is displayed in all capitals (e.g. ``USER12345'') and below it is a long string of upper case letters and numbers. The long string is your password.

field numbers

The field numbers are used to choose what data you want to receive for each symbol.

 number         name            description
 ------         ----            -----------
 0              symbol
 1              bid
 2              ask
 3              last
 4              bid_size        size of bid in 100's
 5              ask_size        size of ask in 100's
 6              bidID           (Q=Nasdaq)
 7              askID
 8              volume          total volume
 9              last_size       size of last trade
 10             trade_time      time of last trade (HH:MM:SS)
 11             quote_time      time of last quote (HH:MM:SS)
 12             high            high of day
 13             low             low of day
 14             BT              tick, up(U) or down(D)
 15             prev_close      previous close
 16             exch            exchange(q=Nasdaq)
 17             ?               do not use, unknown
 18             ?               do not use, unknown
 19             isld_bid        Island bid
 20             isld_ask        Island ask
 21             isld_vol        Island volume

PREREQUISITES

 Module             Version
 ------             -------
 IO::Socket::INET   1.25
 IO::Select         1.14

AUTHOR

Jeremiah Mahler <[email protected]>

COPYRIGHT

Copyright (c) 2002, Jeremiah Mahler. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.