Finance-IG
view release on metacpan or search on metacpan
Testing/test-record.pl view on Meta::CPAN
#!/usr/bin/env perl
#######################################################################################
#
# This is tthe program that records the potted responses that are used in testing.
# You need a real account to use this, with working password.
#
# The REST::Client used writes the responses to file in Data with a name based on hash of
# request parameters. It also sends the request off just like a regular REST::Client.
# So bear in mind there are 3 types of REST::Client on view here.
# The original and canonical one, the mock version at Finance::IG::REST::Client and the recording version that
# is at Finance::IG::Record::REST::Client and calls the original one as well as skuttling away
# the special files used when the mock version is used.
# For the mock version, the wonderful Package::Alias is used to rename the module so that we use the mock
# instead of the real version.
# For the Recorder, rather more earthy techniques have to be imployed, its a horrible hack, but we need to generate those
# files to make the test data for testing the Finance::IG module.
# This program has more functionality than needed (option parsing) because it was based on a command line utility.
#######################################################################################
use FindBin;
use lib $FindBin::RealBin."/../lib/Finance/IG/Record";
use Finance::IG;
use Getopt::Std;
use Time::Piece;
use strict;
no strict 'refs';
use warnings;
my $ig;
use lib $FindBin::RealBin."/../..";
# This file needs a valid account to do anything useful.
# This will be your account, not mine!
# You can hardcode here or use a credential fiie.
# Running this script will allow you to generate
# new canned test data for new test scripts.
if ( eval (require "credentials.pl") )
{
$ig=Finance::IG->new(cred());
}
else
{
$ig=Finance::IG->new(
username=> "igusername",
password=> "ig_correct_password",
apikey=> "securitykey",
isdemo=>0,
);
}
my %opt;
my $sortlist;
my $valid=getopts('ho:tf:ng:s:S', \%opt);
# t display headers every 10 lines
# n no headers
# f n : use format number
# h help
# g grep
# S print NO summary line
# s sort list
# sort list can be
# a comma seperated list of fields each with an optional minus sign eg
# -s'-profitpc,instrumentName' sorts by profit highest first, and if the same, then orders by name
# Here the following can be used as abbreviations
# n instrumentName
# o open => level
# b bid
# v value => atRisk
# p profitpe
# if no commas
# or a comma seperated list of elements, each of which may be optionally started with - for reverse sort
# the above abbrevs may be used. default is -p,n or -profitpc,instrumentName or -pn
if (exists $opt{s} and defined $opt{s})
{
my @list;
if ($opt{s}=~m/^[-nobvp]+$/)
{
@list=split(//,$opt{s});
}
else
{
@list=split(/,/,$opt{s});
@list=map { s/^-//?('-',$_):$_ } @list;
}
for (@list)
{
$_='instrumentName' if ($_ eq 'n');
$_='level' if ($_ eq 'o');
$_='bid' if ($_ eq 'b');
$_='atrisk' if ($_ eq 'v');
$_='profitpc' if ($_ eq 'p');
}
map { ($list[$_] eq '-') and $list[$_+1]='-'.$list[$_+1]; } (0..$#list);
@list=grep { $_ ne '-' } @list;
( run in 0.625 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )