| gif | history | intraday | java | news | objects | options | quote | soap | spots | tickers | weather | end of day | wddx |

Requests:
 Quote
 Chart
 Lookup
Sample Code:
 Coldfusion
 ASP
 JSP
 PHP
 Perl
 
Perl
Good Examples of using WDDX with Perl are found at Codebits. FinWin owes it's thanks to Dan Luther for the excellent and concise example found below. This example uses the LWP package (Lightweb web protocol - used to make server to server requests), and the WDDX package to deserialize the result.

Perl Example
#!/usr/local/bin/perl
#
# Dan Luther
# Williams Communications Group
#

use WDDX;
use LWP::UserAgent;

$ua = new LWP::UserAgent;                   # Create a user agent object

                                            # Create a request
my $req = new HTTP::Request POST =>'http://www.finwin.com/processct/processquotetag.cfm';

                                            # Set the content type
$req->content_type('application/x-www-form-urlencoded');

                                            # Assign the form content
                                            # Hint: You can use multiple symbols separated by commas
$req->content('username=Bogus&password=Bugus&request=quote&id=186&type=query&symbol=wcg,wmb');


my $res = $ua->request($req);               # Pass request to the user agent and get a response back

if (!$res->is_success)                      # Check the outcome of the response
{
    print "Error retrieving content\n";
    exit;
}

$parser = new WDDX();                       # Assign a new WDDX object

                                            # De-serialize the WDDX XML stream
my $wddx_request = $parser->deserialize( $res->content );
printf "Type: %s\n", $wddx_request->type;   # Print the resulting type (should be "recordset")

$rowCount = $wddx_request->num_rows;        # This keeps the number of rows (quotes) returned by the request
print "Row count: ", $rowCount, "\n";

my $colNames = $wddx_request->names;        # "names" is an array of pointers; we'll keep these handy

                                            # "num_columns" is the count of columns returned per record
print "Columns: ", $wddx_request->num_columns, "\n";

                                            # We'll loop through each row returned
for ( $j=0; $j<$wddx_request->num_rows; $j++  )
{
    $colData = $wddx_request->get_row($j);  # "get_row" returns an array of pointers
    my %quoteInfo = ();                     # Create an empty associative array for ease of use

                                            # looping through all the columns
    for ( $i=0; $i<$wddx_request->num_columns; $i++)
    {
                                            # assign the new element with the contents of the data pointers
        $quoteInfo{$$colNames[$i]} = $$colData[$i];
    }

                                            # standard perl associative array print function
    foreach $key (keys(%quoteInfo))
    {
        print $key, ": ", $quoteInfo{$key}, "\n";
    }

    print "\nVolume for ", $quoteInfo{"SYM"}, ": ", $quoteInfo{"VOLUME"}, "\n";
    print "\n\n";

}

exit;

DTN Market Access
9110 West Dodge Road, Suite 200   Omaha, Nebraska 68114
Copyright 2010, All rights reserved