| 1 | #!/usr/bin/env perl | ||||||||||
| 2 | ############################################################### | ||||||||||
| 3 | 1 | ▶ | use FindBin; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use lib $FindBin::RealBin; # for special REST::Client | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use lib $FindBin::RealBin."/../lib"; # for IG | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | #use lib "$FindBin::RealBin/../lib/Finance/IG"; | ||||||||||
| 7 | #use lib $FindBin::RealBin."/Record"; # for other special REST::Client that records. | ||||||||||
| 8 | 1 | ▶ | use Time::Piece; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | #$INC{'REST/Client.pm'} =~m#Testing/REST/Client.pm# or | ||||||||||
| 12 | #$INC{'REST/Client.pm'} =~m#Testing/Record/REST/Client.pm# or | ||||||||||
| 13 | # die "Using wrong REST::Client ".$INC{'REST/Client.pm'}; | ||||||||||
| 14 | |||||||||||
| 15 | use Package::Alias | ||||||||||
| 16 | 1 | ▶ | 'REST::Client'=>'Finance::IG::REST::Client' | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ; | |||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | use Finance::IG; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | my $ig; | |||||||||
| 22 | |||||||||||
| 23 | # with Testing::Record::REST::Client need correct data | ||||||||||
| 24 | 1 | $ig=Finance::IG->new( | |||||||||
| 25 | username=> "igusername", | ||||||||||
| 26 | password=> "ig_correct_password", | ||||||||||
| 27 | apikey=> "securitykey", | ||||||||||
| 28 | isdemo=>0, | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | 1 | $ig->login(); | |||||||||
| 32 | |||||||||||
| 33 | #my $a=$ig->history('2020-10-29T00:00','2020-10-29'); | ||||||||||
| 34 | # my $a=$ig->history('2020-10-29T00:00',localtime->strftime("%Y-%m-%d")); | ||||||||||
| 35 | |||||||||||
| 36 | 1 | my $aa; | |||||||||
| 37 | 1 | my $page=0; | |||||||||
| 38 | 1 | my @transactions; | |||||||||
| 39 | # while ($aa=$ig->transactions(++$page,(scalar localtime)-10*30*24*3600,scalar localtime)) | ||||||||||
| 40 | #while ($aa=$ig->transactions(++$page,Time::Piece->strptime("2020-01-01","%Y-%m-%d-%H.%M"),scalar localtime)) | ||||||||||
| 41 | 1 | ▶ | while ($aa=$ig->transactions(++$page,Time::Piece->strptime("2020-01-01-00.00","%Y-%m-%d-%H.%M"),'2020-12-11T18:15:00')) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | { | ||||||||||
| 43 | 15 | @$aa=grep { $_->{status} ne 'REJECTED' } @$aa; | |||||||||
| 44 | 15 | push(@transactions,@$aa); | |||||||||
| 45 | |||||||||||
| 46 | # print @transactions+0, "\n"; | ||||||||||
| 47 | } | ||||||||||
| 48 | # 2020-07-08T01:06:12 | ||||||||||
| 49 | 1 | @transactions=sort { $b->{dateUtc} cmp $a->{dateUtc} } @transactions; | |||||||||
| 50 | |||||||||||
| 51 | 1 | for $p1 (@transactions) | |||||||||
| 52 | { | ||||||||||
| 53 | 727 | for my $key (sort keys %$p1) | |||||||||
| 54 | { | ||||||||||
| 55 | # print "key $key\n"; | ||||||||||
| 56 | 9451 | ▶ | if ($key eq 'profitAndLoss') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | { | ||||||||||
| 58 | 727 | $p1->{$key}=~s/\xA3/£/g; | |||||||||
| 59 | 727 | $p1->{$key}=~s/£-/-£/; | |||||||||
| 60 | } | ||||||||||
| 61 | 9451 | ▶ | if (ref($p1->{$key}) eq 'JSON::PP::Boolean') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | { | ||||||||||
| 63 | 727 | ▶ | $p1->{$key}=$p1->{$key}?1:0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | } | ||||||||||
| 67 | } | ||||||||||
| 68 | 1 | my $format="%-25sdateUtc %-25sopenDateUtc %30sinstrumentName %6ssize %10sprofitAndLoss %8stransactionType %sopenLevel %9.2fcloseLevel\n"; | |||||||||
| 69 | #my $format="%-25sdateUtc %-25sopenDateUtc %30sinstrumentName %6ssize %10sprofitAndLoss %8stransactionType %9.2fopenLevel %9.2fcloseLevel\n"; | ||||||||||
| 70 | # my $format="%-20sdate %10sinstrumentName %-60sdescription %4.2fsize %sstatus\n"; | ||||||||||
| 71 | 1 | $ig->printpos("stdout","",$format); | |||||||||
| 72 | 1 | map { $ig->printpos("stdout",$_,$format); } @transactions; | |||||||||
| 73 | 1 | exit; | |||||||||
| 74 | |||||||||||
| 75 | # print the following keys in a typical transaction | ||||||||||
| 76 | #key cashTransaction | ||||||||||
| 77 | #key closeLevel | ||||||||||
| 78 | #key currency | ||||||||||
| 79 | #key date | ||||||||||
| 80 | #key dateUtc | ||||||||||
| 81 | #key instrumentName | ||||||||||
| 82 | #key openDateUtc | ||||||||||
| 83 | #key openLevel | ||||||||||
| 84 | #key period | ||||||||||
| 85 | #key profitAndLoss | ||||||||||
| 86 | #key reference | ||||||||||
| 87 | #key size | ||||||||||
| 88 | |||||||||||
| 89 | |||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | |||||||||||
| 93 | |||||||||||
| 94 | 0 | if (0) | |||||||||
| 95 | { | ||||||||||
| 96 | for $p1 (@transactions) | ||||||||||
| 97 | { | ||||||||||
| 98 | printf "*****\n"; | ||||||||||
| 99 | # print $p1->{date} ."\n"; | ||||||||||
| 100 | for my $key (sort keys %$p1) | ||||||||||
| 101 | { | ||||||||||
| 102 | next if $key eq 'dealId'; | ||||||||||
| 103 | next if $key eq 'epic'; | ||||||||||
| 104 | next if $key eq 'currency'; | ||||||||||
| 105 | next if (grep { $key eq $_ } (qw/reference limitLevel trailingStopDistance guaranteedStop trailingStep Distance limitDistance stopLevel goodTillDate period dealReference stopDistance/)); | ||||||||||
| 106 | if ($key eq 'profitAndLoss') | ||||||||||
| 107 | { | ||||||||||
| 108 | $p1->{$key}=~s/\xA3/£/g; | ||||||||||
| 109 | $p1->{$key}=~s/£-/-£/; | ||||||||||
| 110 | } | ||||||||||
| 111 | if (ref($p1->{$key}) eq 'JSON::PP::Boolean') | ||||||||||
| 112 | { | ||||||||||
| 113 | $p1->{$key}=$p1->{$key}?1:0; | ||||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | print "key $key is ".(ref($p1->{$key})?ref($p1->{$key}):$p1->{$key})."\n"; | ||||||||||
| 117 | } | ||||||||||
| 118 | } | ||||||||||
| 119 | exit; | ||||||||||
| 120 | } | ||||||||||
| 121 | 0 | my $format="%-20sdate %20sinstrumentName %6ssize %10sprofitAndLoss %8stransactionType \n"; | |||||||||
| 122 | # my $format="%-20sdate %10sinstrumentName %-60sdescription %4.2fsize %sstatus\n"; | ||||||||||
| 123 | 0 | $ig->printpos("stdout","",$format); | |||||||||
| 124 | 0 | map { $ig->printpos("stdout",$_,$format); } @transactions; | |||||||||
| 125 | |||||||||||
| 126 | |||||||||||