| 1 | #!/usr/bin/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 | 0 | 'REST::Client'=>'Finance::IG::REST::Client' | |
| 17 | 1 | ▶ | ; |
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||
| 18 | |||
| 19 | use Finance::IG; | ||
| 20 | use JSON; | ||
| 21 | my $ig; | ||
| 22 | |||
| 23 | # with Testing::Record::REST::Client need correct data | ||
| 24 | $ig=Finance::IG->new( | ||
| 25 | username=> "igusername", | ||
| 26 | password=> "ig_correct_password", | ||
| 27 | apikey=> "securitykey", | ||
| 28 | isdemo=>0, | ||
| 29 | ); | ||
| 30 | |||
| 31 | $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 | my $aa; | ||
| 37 | my $page=0; | ||
| 38 | 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 | while ($aa=$ig->transactions(++$page,Time::Piece->strptime("2020-01-01","%Y-%m-%d-%H.%M"),'2020-12-11T18:15:00')) | ||
| 42 | { | ||
| 43 | @$aa=grep { $_->{status} ne 'REJECTED' } @$aa; | ||
| 44 | push(@transactions,@$aa); | ||
| 45 | |||
| 46 | # print @transactions+0, "\n"; | ||
| 47 | } | ||
| 48 | # 2020-07-08T01:06:12 | ||
| 49 | @transactions=sort { $b->{dateUtc} cmp $a->{dateUtc} } @transactions; | ||
| 50 | |||
| 51 | for $p1 (@transactions) | ||
| 52 | { | ||
| 53 | for my $key (sort keys %$p1) | ||
| 54 | { | ||
| 55 | # print "key $key\n"; | ||
| 56 | if ($key eq 'profitAndLoss') | ||
| 57 | { | ||
| 58 | $p1->{$key}=~s/\xA3/£/g; | ||
| 59 | $p1->{$key}=~s/£-/-£/; | ||
| 60 | } | ||
| 61 | if (ref($p1->{$key}) eq 'JSON::PP::Boolean') | ||
| 62 | { | ||
| 63 | $p1->{$key}=$p1->{$key}?1:0; | ||
| 64 | } | ||
| 65 | |||
| 66 | } | ||
| 67 | } | ||
| 68 | 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 | $ig->printpos("stdout","",$format); | ||
| 72 | map { $ig->printpos("stdout",$_,$format); } @transactions; | ||
| 73 | 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 | 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 | my $format="%-20sdate %20sinstrumentName %6ssize %10sprofitAndLoss %8stransactionType \n"; | ||
| 122 | # my $format="%-20sdate %10sinstrumentName %-60sdescription %4.2fsize %sstatus\n"; | ||
| 123 | $ig->printpos("stdout","",$format); | ||
| 124 | map { $ig->printpos("stdout",$_,$format); } @transactions; | ||
| 125 | |||
| 126 | |||