Finance-IG
view release on metacpan or search on metacpan
Testing/test-record.pl view on Meta::CPAN
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,
script/igdisp.pl view on Meta::CPAN
use Finance::IG;
use Getopt::Std;
use Time::Piece;
use strict;
no strict 'refs';
use warnings;
my %opt;
my @credentials=(
$FindBin::RealBin.'/../../credentials.pl' ,
$FindBin::RealBin.'/../credentials.pl',
$FindBin::RealBin.'/credentials.pl',
'./credentials.pl',
$ENV{HOME}.'/.config/IG/credentials.pl',
);
our $VERSION=0.103;
######### code for multiiple -n x arguments treat as single joined with |. Not handled with getopts.
$opt{n}=[];
for my $i (0..$#ARGV)
{
next if (!defined $ARGV[$i]);
if ($ARGV[$i] eq '-n')
{
script/igdisp.pl view on Meta::CPAN
my $ig;
# IG Credentials needed.
# You can add them to enviroment variables as bellow or
# directly hardcode them below.
# It can be useful to have a demo account to, this should be a seperate instance of the
# object.
my $capital; # hardcode your capital here if you want.
$opt{c}.='/credentials.pl' if ($opt{c} and ! -f $opt{c});
unshift(@credentials,$opt{c}) if ($opt{c});
if ($opt{e})
{
if ($ENV{IGUSER} and $ENV{IGPASS} and $ENV{IGAPIKEY})
{
print "Environment variables IGUSER, and IGPASS. and IGAPIKEY
are all set and accessible so will use those.\n";
exit 1;
}
script/igdisp.pl view on Meta::CPAN
$ig=Finance::IG->new(
username=> $ENV{IGUSER},
password=> $ENV{IGPASS},
apikey=> $ENV{IGAPIKEY},
isdemo=>0,
col=>0,
);
}
else
{
# eval { require $FindBin::RealBin.'/../../credentials.pl' } or
# eval { require $FindBin::RealBin.'/../credentials.pl' } or
# eval { require $FindBin::RealBin.'/credentials.pl' } or
# eval { require './credentials.pl' } or
my $reqok=0;
map { $reqok ||=eval { require $_ } } @credentials;
$reqok or die "Need a credentials.pl file, looks something like this but contains actual metrobank login credentials:
sub cred
{
return {
username=>'', # Your ig username
password=>'', # Your ig password
apikey=>'' , # Your ig apikey
}
};
1;
You can alternatively use 3 environment variables named IGUSER,IGPASSWORD, IGAPIKEY.
The credentials file is searched for in the following paths:
@credentials
You can also use -c path or file.
" ;
$ig=Finance::IG->new(cred(),isdemo=>0,col=>0);
# This hack allows you to set your starting capital in the credentials file if you wish
my %x=cred();
$capital//=$x{capital};
}
if ($opt{e})
{
my ($e)=grep { m/credentials/ } keys %INC;
$e=~s#/[^/]+/\.\.##g;
$e=~s#/[^/]+/\.\.##g;
print "credentials.pl from : ".$e."\n";
exit;
}
# map { $ENV{$_}//='' } qw(IGUSER IGPASS IGAPIKEY); # empty allowed but caught, undef not allowed
#$ig=Finance::IG->new(
# username=> $ENV{IGUSER},
# password=> $ENV{IGPASS},
# apikey=> $ENV{IGAPIKEY},
# isdemo=>0,
#);
die "missing credentials username, try setting the environment variable IGUSER" if ($ig->username eq '');
die "missing credentials password, try setting the environment variable IGPASS" if ($ig->username eq '');
die "missing credentials apikey, try setting the environment variable IGAPIKEY" if ($ig->username eq '');
my $sortlist;
# -o auto-generate a time based file and use this to send output to
# 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
script/igdisp.pl view on Meta::CPAN
print "
This program is both an example of usage and a practical utility in its own right.
It will print out your spreadbet positions in IG in various ways using your
username, password and apikey. These can be supplied in a cedentials.pl file in the script directory
or 1 or 2 directories up or the current directory. Or you can set
the environment variables IGPASS, IGUSER, IGAPIKEY.
The default display is decending order of percent profit. Various formats are possible.
-a n aggregate 1 (default) , nonaggregate 0 = show individual holdings
-e explain where credentials for login are coming from, then exit.
-o Send output to an autogenerated, time based file.
-f n use one of the inbuilt formats 1 to 5. Or provide the format to use.
-F print the current format and exit .
-h this message and exit
-n xxx use xxx as a pattern in name to grep for particular positions. Can use | for or. (Must be quoted)
multipl -n allowed.
-S print no summary line.
-N toggle printing of headers.
-t print title lines every 10 lines.
-s x Sort output by x where x is a comma seperated list of fields
( run in 0.240 second using v1.01-cache-2.11-cpan-4d50c553e7e )